drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [31/45] drill git commit: DRILL-3987: (MOVE) Move logical expressions and operators out of common. Move to new drill-logical model.
Date Fri, 13 Nov 2015 02:38:01 GMT
http://git-wip-us.apache.org/repos/asf/drill/blob/44dea433/logical/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java
----------------------------------------------------------------------
diff --git a/logical/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java
b/logical/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java
new file mode 100644
index 0000000..7cf1477
--- /dev/null
+++ b/logical/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java
@@ -0,0 +1,118 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.common.expression.parser;
+
+import java.io.IOException;
+
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RecognitionException;
+import org.apache.drill.common.expression.ExpressionStringBuilder;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.expression.parser.ExprParser.parse_return;
+import org.apache.drill.test.DrillTest;
+import org.junit.Test;
+
+public class TreeTest extends DrillTest {
+
+  @Test
+  public void testIfWithCase() throws Exception{
+    testExpressionParsing("if ($F1) then case when (_MAP.R_NAME = 'AFRICA') then 2 else 4
end else if(4==3) then 1 else if(x==3) then 7 else (if(2==1) then 6 else 4 end) end");
+  }
+
+  @Test
+  public void testAdd() throws Exception{
+    testExpressionParsing("2+2");
+  }
+
+  @Test
+  public void testIf() throws Exception{
+    testExpressionParsing("if ('blue.red') then 'orange' else if (false) then 1 else 0 end");
+  }
+
+  @Test
+  public void testQuotedIdentifier() throws Exception{
+    testExpressionParsing("`hello friend`.`goodbye`");
+  }
+
+  @Test
+  public void testSpecialQuoted() throws Exception{
+    testExpressionParsing("`*0` + `*` ");
+  }
+
+  @Test
+  public void testQuotedIdentifier2() throws Exception{
+    testExpressionParsing("`hello friend`.goodbye");
+  }
+
+  @Test
+  public void testComplexIdentifier() throws Exception{
+    testExpressionParsing("goodbye[4].`hello`");
+  }
+
+  @Test // DRILL-2606
+  public void testCastToBooleanExpr() throws Exception{
+    testExpressionParsing("cast( (cast( (`bool_col` ) as VARCHAR(100) ) ) as BIT )");
+  }
+
+  private LogicalExpression parseExpression(String expr) throws RecognitionException, IOException{
+
+    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
+    CommonTokenStream tokens = new CommonTokenStream(lexer);
+
+//    tokens.fill();
+//    for(Token t : (List<Token>) tokens.getTokens()){
+//      System.out.println(t + "" + t.getType());
+//    }
+//    tokens.rewind();
+
+    ExprParser parser = new ExprParser(tokens);
+    parse_return ret = parser.parse();
+
+    return ret.e;
+
+  }
+
+  private String serializeExpression(LogicalExpression expr){
+
+    ExpressionStringBuilder b = new ExpressionStringBuilder();
+    StringBuilder sb = new StringBuilder();
+    expr.accept(b, sb);
+    return sb.toString();
+  }
+
+  /**
+   * Attempt to parse an expression.  Once parsed, convert it to a string and then parse
it again to make sure serialization works.
+   * @param expr
+   * @throws RecognitionException
+   * @throws IOException
+   */
+  private void testExpressionParsing(String expr) throws RecognitionException, IOException{
+    System.out.println("-----" + expr + "-----");
+    LogicalExpression e = parseExpression(expr);
+
+    String newStringExpr = serializeExpression(e);
+    System.out.println(newStringExpr);
+    LogicalExpression e2 = parseExpression(newStringExpr);
+    //Assert.assertEquals(e, e2);
+
+  }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/44dea433/logical/src/test/java/org/apache/drill/common/logical/data/OrderTest.java
----------------------------------------------------------------------
diff --git a/logical/src/test/java/org/apache/drill/common/logical/data/OrderTest.java b/logical/src/test/java/org/apache/drill/common/logical/data/OrderTest.java
new file mode 100644
index 0000000..80b4e3c
--- /dev/null
+++ b/logical/src/test/java/org/apache/drill/common/logical/data/OrderTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.common.logical.data;
+
+import static org.junit.Assert.*;
+
+import java.sql.SQLException;
+
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.logical.data.Order.Ordering;
+import org.apache.calcite.rel.RelFieldCollation;
+import org.apache.calcite.rel.RelFieldCollation.Direction;
+import org.apache.calcite.rel.RelFieldCollation.NullDirection;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.*;
+
+public class OrderTest {
+
+  //////////
+  // Order.Ordering tests:
+
+  // "Round trip" tests that strings from output work as input:
+
+  @Test
+  public void test_Ordering_roundTripAscAndNullsFirst() {
+    Ordering src = new Ordering( Direction.ASCENDING, null, NullDirection.FIRST);
+    Ordering reconstituted =
+        new Ordering( (LogicalExpression) null, src.getOrder(), src.getNullDirection().toString()
);
+    assertThat( reconstituted.getDirection(), equalTo( RelFieldCollation.Direction.ASCENDING
 ) );
+    assertThat( reconstituted.getNullDirection(), equalTo( NullDirection.FIRST  ) );
+  }
+
+  @Test
+  public void test_Ordering_roundTripDescAndNullsLast() {
+    Ordering src = new Ordering( Direction.DESCENDING, null, NullDirection.LAST);
+    Ordering reconstituted =
+        new Ordering( (LogicalExpression) null, src.getOrder(), src.getNullDirection().toString()
);
+    assertThat( reconstituted.getDirection(), equalTo( RelFieldCollation.Direction.DESCENDING
 ) );
+    assertThat( reconstituted.getNullDirection(), equalTo( NullDirection.LAST  ) );
+  }
+
+  @Test
+  public void test_Ordering_roundTripDescAndNullsUnspecified() {
+    Ordering src = new Ordering( Direction.DESCENDING, null, NullDirection.UNSPECIFIED);
+    Ordering reconstituted =
+        new Ordering( (LogicalExpression) null, src.getOrder(), src.getNullDirection().toString()
);
+    assertThat( reconstituted.getDirection(), equalTo( RelFieldCollation.Direction.DESCENDING
 ) );
+    assertThat( reconstituted.getNullDirection(), equalTo( NullDirection.UNSPECIFIED  ) );
+  }
+
+
+  // Basic input validation:
+
+  @Test( expected = DrillRuntimeException.class )  // (Currently.)
+  public void test_Ordering_garbageOrderRejected() {
+    new Ordering( (LogicalExpression) null, "AS CE ND IN G", (String) null );
+  }
+
+  @Test( expected = DrillRuntimeException.class )  // (Currently.)
+  public void test_Ordering_garbageNullOrderingRejected() {
+    new Ordering( (LogicalExpression) null, (String) null, "HIGH" );
+  }
+
+
+  // Defaults-value/null-strings test:
+
+  @Test
+  public void testOrdering_nullStrings() {
+    Ordering ordering = new Ordering( (LogicalExpression) null, null, null );
+    assertThat( ordering.getDirection(), equalTo( RelFieldCollation.Direction.ASCENDING )
);
+    assertThat( ordering.getNullDirection(), equalTo( RelFieldCollation.NullDirection.UNSPECIFIED
) );
+    assertThat( ordering.getOrder(), equalTo( "ASC" ) );
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/44dea433/logical/src/test/java/org/apache/drill/storage/CheckStorageConfig.java
----------------------------------------------------------------------
diff --git a/logical/src/test/java/org/apache/drill/storage/CheckStorageConfig.java b/logical/src/test/java/org/apache/drill/storage/CheckStorageConfig.java
new file mode 100644
index 0000000..090b8f4
--- /dev/null
+++ b/logical/src/test/java/org/apache/drill/storage/CheckStorageConfig.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.storage;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collection;
+
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.config.LogicalPlanPersistence;
+import org.apache.drill.common.logical.LogicalPlan;
+import org.apache.drill.common.logical.StoragePluginConfig;
+import org.apache.drill.common.scanner.ClassPathScanner;
+import org.apache.drill.common.scanner.persistence.ScanResult;
+import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.test.DrillTest;
+import org.junit.Test;
+
+public class CheckStorageConfig extends DrillTest {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CheckStorageConfig.class);
+
+  @Test
+  public void ensureStorageEnginePickup() {
+    DrillConfig config = DrillConfig.create();
+    ScanResult scan = ClassPathScanner.fromPrescan(config);
+    Collection<?> engines = scan.getImplementations(StoragePluginConfig.class);
+    assertEquals(engines.size(), 1);
+  }
+
+  @Test
+  public void checkPlanParsing() throws Exception{
+    DrillConfig config = DrillConfig.create();
+    ScanResult scan = ClassPathScanner.fromPrescan(config);
+    LogicalPlan plan = LogicalPlan.parse(new LogicalPlanPersistence(config, scan), FileUtils.getResourceAsString("/storage_engine_plan.json"));
+  }
+}


Mime
View raw message