flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aljos...@apache.org
Subject [1/2] flink git commit: [FLINK-1997][table] Add <> and != for un-equal in expressions
Date Fri, 08 May 2015 14:31:50 GMT
Repository: flink
Updated Branches:
  refs/heads/master 2939fba3f -> 84dcb7c20


[FLINK-1997][table] Add <> and != for un-equal in expressions


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/3b8f60e9
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/3b8f60e9
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/3b8f60e9

Branch: refs/heads/master
Commit: 3b8f60e9b6f65485db280124e5368f111b558e27
Parents: 2939fba
Author: Aljoscha Krettek <aljoscha.krettek@gmail.com>
Authored: Fri May 8 14:55:38 2015 +0200
Committer: Aljoscha Krettek <aljoscha.krettek@gmail.com>
Committed: Fri May 8 14:55:38 2015 +0200

----------------------------------------------------------------------
 .../api/table/parser/ExpressionParser.scala     | 10 +++-----
 .../flink/api/java/table/test/FilterITCase.java | 25 +++++++++++++++++++-
 2 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/3b8f60e9/flink-staging/flink-table/src/main/scala/org/apache/flink/api/table/parser/ExpressionParser.scala
----------------------------------------------------------------------
diff --git a/flink-staging/flink-table/src/main/scala/org/apache/flink/api/table/parser/ExpressionParser.scala
b/flink-staging/flink-table/src/main/scala/org/apache/flink/api/table/parser/ExpressionParser.scala
index 500f39f..7637146 100644
--- a/flink-staging/flink-table/src/main/scala/org/apache/flink/api/table/parser/ExpressionParser.scala
+++ b/flink-staging/flink-table/src/main/scala/org/apache/flink/api/table/parser/ExpressionParser.scala
@@ -139,15 +139,11 @@ object ExpressionParser extends JavaTokenParsers with PackratParsers
{
 
   // Comparison
 
-  lazy val equalTo: PackratParser[Expression] = term ~ "===" ~ term ^^ {
+  lazy val equalTo: PackratParser[Expression] = term ~ ("===" | "=") ~ term ^^ {
     case l ~ _ ~ r => EqualTo(l, r)
   }
 
-  lazy val equalToAlt: PackratParser[Expression] = term ~ "=" ~ term ^^ {
-    case l ~ _ ~ r => EqualTo(l, r)
-  }
-
-  lazy val notEqualTo: PackratParser[Expression] = term ~ "!==" ~ term ^^ {
+  lazy val notEqualTo: PackratParser[Expression] = term ~ ("!==" | "!=" | "<>") ~ term
^^ {
     case l ~ _ ~ r => NotEqualTo(l, r)
   }
 
@@ -168,7 +164,7 @@ object ExpressionParser extends JavaTokenParsers with PackratParsers {
   }
 
   lazy val comparison: PackratParser[Expression] =
-      equalTo | equalToAlt | notEqualTo |
+      equalTo | notEqualTo |
       greaterThan | greaterThanOrEqual |
       lessThan | lessThanOrEqual | term
 

http://git-wip-us.apache.org/repos/asf/flink/blob/3b8f60e9/flink-staging/flink-table/src/test/java/org/apache/flink/api/java/table/test/FilterITCase.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-table/src/test/java/org/apache/flink/api/java/table/test/FilterITCase.java
b/flink-staging/flink-table/src/test/java/org/apache/flink/api/java/table/test/FilterITCase.java
index 03ff2e7..d40b6a0 100644
--- a/flink-staging/flink-table/src/test/java/org/apache/flink/api/java/table/test/FilterITCase.java
+++ b/flink-staging/flink-table/src/test/java/org/apache/flink/api/java/table/test/FilterITCase.java
@@ -118,7 +118,30 @@ public class FilterITCase extends MultipleProgramsTestBase {
 				tableEnv.toTable(input, "a, b, c");
 
 		Table result = table
-				.filter(" a % 2 === 0 ");
+				.filter(" a % 2 = 0 ");
+
+		DataSet<Row> ds = tableEnv.toSet(result, Row.class);
+		ds.writeAsText(resultPath, FileSystem.WriteMode.OVERWRITE);
+
+		env.execute();
+
+		expected = "2,2,Hello\n" + "4,3,Hello world, how are you?\n" + "6,3,Luke Skywalker\n" +
"8,4," +
+				"Comment#2\n" + "10,4,Comment#4\n" + "12,5,Comment#6\n" + "14,5,Comment#8\n" + "16,6,"
+
+				"Comment#10\n" + "18,6,Comment#12\n" + "20,6,Comment#14\n";
+	}
+
+	@Test
+	public void testNotEquals() throws Exception {
+		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
+		TableEnvironment tableEnv = new TableEnvironment();
+
+		DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.get3TupleDataSet(env);
+
+		Table table =
+				tableEnv.toTable(input, "a, b, c");
+
+		Table result = table
+				.filter("!( a % 2 <> 0 ) ");
 
 		DataSet<Row> ds = tableEnv.toSet(result, Row.class);
 		ds.writeAsText(resultPath, FileSystem.WriteMode.OVERWRITE);


Mime
View raw message