want write Specified field from dataset to output file

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

want write Specified field from dataset to output file

hagersaleh
I want write Specified field from dataset to output file
I want write field 2 to output file
example
DataSet<Customer3> customers=env.readCsvFile("/home/hadoop/Desktop/Dataset/customer.csv")
                    .fieldDelimiter('|')
                    .includeFields(11000010).ignoreFirstLine()
                    .tupleType(Customer3.class);
                    customers = customers.filter(new FilterFunction<Customer3>()
                        {
                            @Override                    
                            public boolean filter(Customer3 c) {
                             
                           
                            c.getField(2).toString().equals("AUTOMOBILE");
                           }
                      return true;
                           
                        }
                });
               customers.print();      
                customers.writeAsCsv("/home/hadoop/Desktop/Dataset/out2.csv", "\n", "|");
               }
Reply | Threaded
Open this post in threaded view
|

Re: want write Specified field from dataset to output file

rmetzger0
Hi,

please have a look at the programming guide on how to write results to an output file: http://ci.apache.org/projects/flink/flink-docs-master/apis/programming_guide.html#data-sinks

In your case, I would recommend:

customers.writeAsFormattedText("file:///path/to/the/result/file",
    new TextFormatter<Customer3>>() {
        public String format (Customer3 value) {
            return value.getField(2).toString();
        }
    });


On Tue, May 12, 2015 at 9:20 AM, hagersaleh <[hidden email]> wrote:
I want write Specified field from dataset to output file
I want write field 2 to output file
example
DataSet<Customer3>
customers=env.readCsvFile("/home/hadoop/Desktop/Dataset/customer.csv")
                    .fieldDelimiter('|')
                    .includeFields(11000010).ignoreFirstLine()
                    .tupleType(Customer3.class);
                    customers = customers.filter(new
FilterFunction<Customer3>()
                        {
                            @Override
                            public boolean filter(Customer3 c) {


                            c.getField(2).toString().equals("AUTOMOBILE");
                           }
                      return true;

                        }
                });
               customers.print();

customers.writeAsCsv("/home/hadoop/Desktop/Dataset/out2.csv", "\n", "|");
               }




--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/want-write-Specified-field-from-dataset-to-output-file-tp1223.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: want write Specified field from dataset to output file

hagersaleh
when use the solve display error message

 cannot find symbol
new TextFormatter<Customer2>() {
symbol: class TextFormatter
location: class TPCHQuery3
Note: /home/hadoop/Desktop/sub_query/src/org/apache/flink/examples/java/relational/TPCHQuery3.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error1 warning
Reply | Threaded
Open this post in threaded view
|

Re: want write Specified field from dataset to output file

hagersaleh
I solve error when use import org.apache.flink.api.java.io.TextOutputFormat.TextFormatter;
very thanks