展平RDD中的Scala地图

时间:2015-04-23 22:32:33

标签: scala apache-spark

我的RDD看起来像:

uidProcessedKeywords: org.apache.spark.rdd.RDD[(Long, Map[String,Double])]

如何在RDD中展平地图以获得此结果:

org.apache.spark.rdd.RDD[(Long, String, Double)]

1 个答案:

答案 0 :(得分:7)

public static void sendData(String user, int pizzaID, int pizzaSize,  double income,
                         String address, String clientName, String telephone){

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.myservice.byethost33.com/insertOrder.php");

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
            nameValuePairs.add(new BasicNameValuePair("user", user));
            nameValuePairs.add(new BasicNameValuePair("pizzaID", String.valueOf(pizzaID)));
            nameValuePairs.add(new BasicNameValuePair("pizzaSize", String.valueOf(pizzaSize)));
            nameValuePairs.add(new BasicNameValuePair("income", String.valueOf(income)));
            nameValuePairs.add(new BasicNameValuePair("address", address));
            nameValuePairs.add(new BasicNameValuePair("clientName", clientName));
            nameValuePairs.add(new BasicNameValuePair("telephone", telephone));

            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }