You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by hagersaleh <lo...@yahoo.com> on 2015/06/07 14:57:48 UTC
when return value from linkedlist or map and use in filter function
display error
when return value from linkedlist or map and use in filter function display
error when run program from command line but when run from netbeans not
display error
public static Map<String, Integer> map = new HashMap<String, Integer>();
public static void main(String[] args) throws Exception {
map.put("C_MKTSEGMENT", 2);
ExecutionEnvironment env =
ExecutionEnvironment.getExecutionEnvironment();
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) {
int
index1=Integer.parseInt(map.get("C_MKTSEGMENT").toString());
return c.getField(index1).equals("AUTOMOBILE");
}
});
customers.print();
customers.writeAsCsv("/home/hadoop/Desktop/Dataset/out1.csv",
"\n", "|",WriteMode.OVERWRITE);
env.execute("TPCH Query 3 Example");
}
hadoop@ubuntu:~/Desktop/flink-0.7.0-incubating$ bin/flink run
/home/hadoop/Desktop/where_operation_final/dist/where_operation_final.jar
06/06/2015 13:12:31: Job execution switched to status RUNNING
06/06/2015 13:12:31: CHAIN DataSource (CSV Input (|)
/home/hadoop/Desktop/Dataset/customer.csv) -> Filter
(org.apache.flink.examples.java.relational.TPCHQuery3$1) (1/1) switched to
SCHEDULED
06/06/2015 13:12:31: CHAIN DataSource (CSV Input (|)
/home/hadoop/Desktop/Dataset/customer.csv) -> Filter
(org.apache.flink.examples.java.relational.TPCHQuery3$1) (1/1) switched to
DEPLOYING
06/06/2015 13:12:31: CHAIN DataSource (CSV Input (|)
/home/hadoop/Desktop/Dataset/customer.csv) -> Filter
(org.apache.flink.examples.java.relational.TPCHQuery3$1) (1/1) switched to
RUNNING
06/06/2015 13:12:31: CHAIN DataSource (CSV Input (|)
/home/hadoop/Desktop/Dataset/customer.csv) -> Filter
(org.apache.flink.examples.java.relational.TPCHQuery3$1) (1/1) switched to
FAILED
java.lang.NullPointerException
at
org.apache.flink.examples.java.relational.TPCHQuery3$1.filter(TPCHQuery3.java:73)
at
org.apache.flink.examples.java.relational.TPCHQuery3$1.filter(TPCHQuery3.java:70)
at
org.apache.flink.api.java.operators.translation.PlanFilterOperator$FlatMapFilter.flatMap(PlanFilterOperator.java:47)
at
org.apache.flink.runtime.operators.chaining.ChainedFlatMapDriver.collect(ChainedFlatMapDriver.java:79)
at
org.apache.flink.runtime.operators.DataSourceTask.invoke(DataSourceTask.java:215)
at
org.apache.flink.runtime.execution.RuntimeEnvironment.run(RuntimeEnvironment.java:235)
at java.lang.Thread.run(Thread.java:745)
06/06/2015 13:12:31: Job execution switched to status FAILING
06/06/2015 13:12:31: DataSink(Print to System.out) (1/1) switched to
CANCELED
06/06/2015 13:12:31: DataSink(CsvOutputFormat (path:
/home/hadoop/Desktop/Dataset/out1.csv, delimiter: |)) (1/1) switched to
CANCELED
06/06/2015 13:12:31: Job execution switched to status FAILED
Error: The program execution failed: java.lang.NullPointerException
at
org.apache.flink.examples.java.relational.TPCHQuery3$1.filter(TPCHQuery3.java:73)
at
org.apache.flink.examples.java.relational.TPCHQuery3$1.filter(TPCHQuery3.java:70)
at
org.apache.flink.api.java.operators.translation.PlanFilterOperator$FlatMapFilter.flatMap(PlanFilterOperator.java:47)
at
org.apache.flink.runtime.operators.chaining.ChainedFlatMapDriver.collect(ChainedFlatMapDriver.java:79)
at
org.apache.flink.runtime.operators.DataSourceTask.invoke(DataSourceTask.java:215)
at
org.apache.flink.runtime.execution.RuntimeEnvironment.run(RuntimeEnvironment.java:235)
at java.lang.Thread.run(Thread.java:745)
--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/when-return-value-from-linkedlist-or-map-and-use-in-filter-function-display-error-tp1528.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.
Re: when return value from linkedlist or map and use in filter
function display error
Posted by Robert Metzger <rm...@apache.org>.
Great! I'm happy to hear that it worked.
On Tue, Jun 9, 2015 at 5:28 PM, hagersaleh <lo...@yahoo.com> wrote:
> I can solve problem when final Map<String, Integer> map = new
> HashMap<String, Integer>();
>
> very thanks
> code run in command line not any error
> public static void main(String[] args) throws Exception {
> final Map<String, Integer> map = new HashMap<String, Integer>();
> map.put("C_MKTSEGMENT", 2);
> ExecutionEnvironment env =
> ExecutionEnvironment.getExecutionEnvironment();
> 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) {
>
> Integer index1=map.get("C_MKTSEGMENT");
> return c.getField(index1).equals("AUTOMOBILE");
> }
> });
>
> customers.print();
> customers.writeAsCsv("/home/hadoop/Desktop/Dataset/out1.csv",
> "\n",
> "|",WriteMode.OVERWRITE);
> env.execute("TPCH Query 3 Example");
>
> }
>
>
>
> --
> View this message in context:
> http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/when-return-value-from-linkedlist-or-map-and-use-in-filter-function-display-error-tp1528p1567.html
> Sent from the Apache Flink User Mailing List archive. mailing list archive
> at Nabble.com.
>
Re: when return value from linkedlist or map and use in filter
function display error
Posted by hagersaleh <lo...@yahoo.com>.
I can solve problem when final Map<String, Integer> map = new
HashMap<String, Integer>();
very thanks
code run in command line not any error
public static void main(String[] args) throws Exception {
final Map<String, Integer> map = new HashMap<String, Integer>();
map.put("C_MKTSEGMENT", 2);
ExecutionEnvironment env =
ExecutionEnvironment.getExecutionEnvironment();
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) {
Integer index1=map.get("C_MKTSEGMENT");
return c.getField(index1).equals("AUTOMOBILE");
}
});
customers.print();
customers.writeAsCsv("/home/hadoop/Desktop/Dataset/out1.csv", "\n",
"|",WriteMode.OVERWRITE);
env.execute("TPCH Query 3 Example");
}
--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/when-return-value-from-linkedlist-or-map-and-use-in-filter-function-display-error-tp1528p1567.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.
Re: when return value from linkedlist or map and use in filter
function display error
Posted by hagersaleh <lo...@yahoo.com>.
error dispaly
non-static variable map cannot be referenced from a static context
map.put("C_MKTSEGMENT", 2);
code
public Map<String, Integer> map = new HashMap<String, Integer>();
public static void main(String[] args) throws Exception {
map.put("C_MKTSEGMENT", 2);
ExecutionEnvironment env =
ExecutionEnvironment.getExecutionEnvironment();
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) {
Integer index1=map.get("C_MKTSEGMENT");
return c.getField(index1).equals("AUTOMOBILE");
}
});
customers.print();
customers.writeAsCsv("/home/hadoop/Desktop/Dataset/out1.csv", "\n",
"|",WriteMode.OVERWRITE);
env.execute("TPCH Query 3 Example");
}
when remove static from main method display error not found main method
--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/when-return-value-from-linkedlist-or-map-and-use-in-filter-function-display-error-tp1528p1555.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.
Re: when return value from linkedlist or map and use in filter
function display error
Posted by Robert Metzger <rm...@apache.org>.
What exactly is the error you are getting when using the non-static field?
On Mon, Jun 8, 2015 at 2:41 PM, hagersaleh <lo...@yahoo.com> wrote:
> when use non-static filed display error
> and filter function not show map
>
>
>
>
> --
> View this message in context:
> http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/when-return-value-from-linkedlist-or-map-and-use-in-filter-function-display-error-tp1528p1544.html
> Sent from the Apache Flink User Mailing List archive. mailing list archive
> at Nabble.com.
>
Re: when return value from linkedlist or map and use in filter
function display error
Posted by hagersaleh <lo...@yahoo.com>.
please help
why when run program from netbeans not display error
but when run command line display error
--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/when-return-value-from-linkedlist-or-map-and-use-in-filter-function-display-error-tp1528p1548.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.
Re: when return value from linkedlist or map and use in filter
function display error
Posted by hagersaleh <lo...@yahoo.com>.
when use non-static filed display error
and filter function not show map
--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/when-return-value-from-linkedlist-or-map-and-use-in-filter-function-display-error-tp1528p1544.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.
Re: when return value from linkedlist or map and use in filter
function display error
Posted by Robert Metzger <rm...@apache.org>.
Hi,
the problem is that "map" is a static field.
Can you make the "map" field a non-static variable of the main method? That
should resolve the issue.
On Sun, Jun 7, 2015 at 2:57 PM, hagersaleh <lo...@yahoo.com> wrote:
> when return value from linkedlist or map and use in filter function display
> error when run program from command line but when run from netbeans not
> display error
> public static Map<String, Integer> map = new HashMap<String, Integer>();
> public static void main(String[] args) throws Exception {
> map.put("C_MKTSEGMENT", 2);
>
> ExecutionEnvironment env =
> ExecutionEnvironment.getExecutionEnvironment();
> 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) {
> int
> index1=Integer.parseInt(map.get("C_MKTSEGMENT").toString());
> return c.getField(index1).equals("AUTOMOBILE");
> }
> });
>
> customers.print();
> customers.writeAsCsv("/home/hadoop/Desktop/Dataset/out1.csv",
> "\n", "|",WriteMode.OVERWRITE);
> env.execute("TPCH Query 3 Example");
> }
>
>
> hadoop@ubuntu:~/Desktop/flink-0.7.0-incubating$ bin/flink run
> /home/hadoop/Desktop/where_operation_final/dist/where_operation_final.jar
> 06/06/2015 13:12:31: Job execution switched to status RUNNING
> 06/06/2015 13:12:31: CHAIN DataSource (CSV Input (|)
> /home/hadoop/Desktop/Dataset/customer.csv) -> Filter
> (org.apache.flink.examples.java.relational.TPCHQuery3$1) (1/1) switched to
> SCHEDULED
> 06/06/2015 13:12:31: CHAIN DataSource (CSV Input (|)
> /home/hadoop/Desktop/Dataset/customer.csv) -> Filter
> (org.apache.flink.examples.java.relational.TPCHQuery3$1) (1/1) switched to
> DEPLOYING
> 06/06/2015 13:12:31: CHAIN DataSource (CSV Input (|)
> /home/hadoop/Desktop/Dataset/customer.csv) -> Filter
> (org.apache.flink.examples.java.relational.TPCHQuery3$1) (1/1) switched to
> RUNNING
> 06/06/2015 13:12:31: CHAIN DataSource (CSV Input (|)
> /home/hadoop/Desktop/Dataset/customer.csv) -> Filter
> (org.apache.flink.examples.java.relational.TPCHQuery3$1) (1/1) switched to
> FAILED
> java.lang.NullPointerException
> at
>
> org.apache.flink.examples.java.relational.TPCHQuery3$1.filter(TPCHQuery3.java:73)
> at
>
> org.apache.flink.examples.java.relational.TPCHQuery3$1.filter(TPCHQuery3.java:70)
> at
>
> org.apache.flink.api.java.operators.translation.PlanFilterOperator$FlatMapFilter.flatMap(PlanFilterOperator.java:47)
> at
>
> org.apache.flink.runtime.operators.chaining.ChainedFlatMapDriver.collect(ChainedFlatMapDriver.java:79)
> at
>
> org.apache.flink.runtime.operators.DataSourceTask.invoke(DataSourceTask.java:215)
> at
>
> org.apache.flink.runtime.execution.RuntimeEnvironment.run(RuntimeEnvironment.java:235)
> at java.lang.Thread.run(Thread.java:745)
>
> 06/06/2015 13:12:31: Job execution switched to status FAILING
> 06/06/2015 13:12:31: DataSink(Print to System.out) (1/1) switched to
> CANCELED
> 06/06/2015 13:12:31: DataSink(CsvOutputFormat (path:
> /home/hadoop/Desktop/Dataset/out1.csv, delimiter: |)) (1/1) switched to
> CANCELED
> 06/06/2015 13:12:31: Job execution switched to status FAILED
> Error: The program execution failed: java.lang.NullPointerException
> at
>
> org.apache.flink.examples.java.relational.TPCHQuery3$1.filter(TPCHQuery3.java:73)
> at
>
> org.apache.flink.examples.java.relational.TPCHQuery3$1.filter(TPCHQuery3.java:70)
> at
>
> org.apache.flink.api.java.operators.translation.PlanFilterOperator$FlatMapFilter.flatMap(PlanFilterOperator.java:47)
> at
>
> org.apache.flink.runtime.operators.chaining.ChainedFlatMapDriver.collect(ChainedFlatMapDriver.java:79)
> at
>
> org.apache.flink.runtime.operators.DataSourceTask.invoke(DataSourceTask.java:215)
> at
>
> org.apache.flink.runtime.execution.RuntimeEnvironment.run(RuntimeEnvironment.java:235)
> at java.lang.Thread.run(Thread.java:745)
>
>
>
>
> --
> View this message in context:
> http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/when-return-value-from-linkedlist-or-map-and-use-in-filter-function-display-error-tp1528.html
> Sent from the Apache Flink User Mailing List archive. mailing list archive
> at Nabble.com.
>