You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/11/14 22:32:10 UTC
[02/58] [abbrv] [partial] incubator-calcite git commit: [CALCITE-306]
Standardize code style for "import package.*; "
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java
index d868724..0be06c1 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java
@@ -14,10 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.linq4j.test;
-
-import net.hydromatic.linq4j.expressions.*;
-import net.hydromatic.linq4j.function.Function1;
+package org.apache.calcite.linq4j.test;
+
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.BlockStatement;
+import org.apache.calcite.linq4j.tree.Blocks;
+import org.apache.calcite.linq4j.tree.ClassDeclaration;
+import org.apache.calcite.linq4j.tree.DeclarationStatement;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.FieldDeclaration;
+import org.apache.calcite.linq4j.tree.FunctionExpression;
+import org.apache.calcite.linq4j.tree.MemberDeclaration;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.NewExpression;
+import org.apache.calcite.linq4j.tree.Node;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.linq4j.tree.Types;
+import org.apache.calcite.linq4j.tree.Visitor;
import org.junit.Test;
@@ -25,12 +40,17 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.util.*;
+import java.util.AbstractList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.TreeSet;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
/**
- * Unit test for {@link net.hydromatic.linq4j.expressions.Expression}
+ * Unit test for {@link org.apache.calcite.linq4j.tree.Expression}
* and subclasses.
*/
public class ExpressionTest {
@@ -50,19 +70,19 @@ public class ExpressionTest {
// Print out the expression.
String s = Expressions.toString(lambdaExpr);
assertEquals(
- "new net.hydromatic.linq4j.function.Function1() {\n"
- + " public double apply(double arg) {\n"
- + " return arg + 2.0D;\n"
- + " }\n"
- + " public Object apply(Double arg) {\n"
- + " return apply(\n"
- + " arg.doubleValue());\n"
- + " }\n"
- + " public Object apply(Object arg) {\n"
- + " return apply(\n"
- + " (Double) arg);\n"
- + " }\n"
- + "}\n",
+ "new org.apache.calcite.linq4j.function.Function1() {\n"
+ + " public double apply(double arg) {\n"
+ + " return arg + 2.0D;\n"
+ + " }\n"
+ + " public Object apply(Double arg) {\n"
+ + " return apply(\n"
+ + " arg.doubleValue());\n"
+ + " }\n"
+ + " public Object apply(Object arg) {\n"
+ + " return apply(\n"
+ + " (Double) arg);\n"
+ + " }\n"
+ + "}\n",
s);
// Compile and run the lambda expression.
@@ -92,21 +112,21 @@ public class ExpressionTest {
// Print out the expression.
String s = Expressions.toString(lambdaExpr);
- assertEquals("new net.hydromatic.linq4j.function.Function2() {\n"
- + " public int apply(int key, int key2) {\n"
- + " return key;\n"
- + " }\n"
- + " public Integer apply(Integer key, Integer key2) {\n"
- + " return apply(\n"
- + " key.intValue(),\n"
- + " key2.intValue());\n"
- + " }\n"
- + " public Integer apply(Object key, Object key2) {\n"
- + " return apply(\n"
- + " (Integer) key,\n"
- + " (Integer) key2);\n"
- + " }\n"
- + "}\n",
+ assertEquals("new org.apache.calcite.linq4j.function.Function2() {\n"
+ + " public int apply(int key, int key2) {\n"
+ + " return key;\n"
+ + " }\n"
+ + " public Integer apply(Integer key, Integer key2) {\n"
+ + " return apply(\n"
+ + " key.intValue(),\n"
+ + " key2.intValue());\n"
+ + " }\n"
+ + " public Integer apply(Object key, Object key2) {\n"
+ + " return apply(\n"
+ + " (Integer) key,\n"
+ + " (Integer) key2);\n"
+ + " }\n"
+ + "}\n",
s);
}
@@ -315,15 +335,15 @@ public class ExpressionTest {
final ParameterExpression paramX =
Expressions.parameter(String.class, "x");
assertEquals(
- "new net.hydromatic.linq4j.function.Function1() {\n"
- + " public int apply(String x) {\n"
- + " return x.length();\n"
- + " }\n"
- + " public Object apply(Object x) {\n"
- + " return apply(\n"
- + " (String) x);\n"
- + " }\n"
- + "}\n",
+ "new org.apache.calcite.linq4j.function.Function1() {\n"
+ + " public int apply(String x) {\n"
+ + " return x.length();\n"
+ + " }\n"
+ + " public Object apply(Object x) {\n"
+ + " return apply(\n"
+ + " (String) x);\n"
+ + " }\n"
+ + "}\n",
Expressions.toString(
Expressions.lambda(
Function1.class,
@@ -334,9 +354,9 @@ public class ExpressionTest {
// 1-dimensional array with initializer
assertEquals(
"new String[] {\n"
- + " \"foo\",\n"
- + " null,\n"
- + " \"bar\\\"baz\"}",
+ + " \"foo\",\n"
+ + " null,\n"
+ + " \"bar\\\"baz\"}",
Expressions.toString(
Expressions.newArrayInit(
String.class,
@@ -347,12 +367,12 @@ public class ExpressionTest {
// 2-dimensional array with initializer
assertEquals(
"new String[][] {\n"
- + " new String[] {\n"
- + " \"foo\",\n"
- + " \"bar\"},\n"
- + " null,\n"
- + " new String[] {\n"
- + " null}}",
+ + " new String[] {\n"
+ + " \"foo\",\n"
+ + " \"bar\"},\n"
+ + " null,\n"
+ + " new String[] {\n"
+ + " null}}",
Expressions.toString(
Expressions.newArrayInit(
String.class,
@@ -431,9 +451,9 @@ public class ExpressionTest {
// array of primitives
assertEquals(
"new int[] {\n"
- + " 1,\n"
- + " 2,\n"
- + " -1}",
+ + " 1,\n"
+ + " 2,\n"
+ + " -1}",
Expressions.toString(
Expressions.constant(new int[]{1, 2, -1})));
@@ -498,8 +518,8 @@ public class ExpressionTest {
// objects and nulls
assertEquals(
"new String[] {\n"
- + " \"foo\",\n"
- + " null}",
+ + " \"foo\",\n"
+ + " null}",
Expressions.toString(
Expressions.constant(new String[] {"foo", null})));
@@ -511,15 +531,15 @@ public class ExpressionTest {
// enum
assertEquals(
- "net.hydromatic.linq4j.test.ExpressionTest.MyEnum.X",
+ "org.apache.calcite.linq4j.test.ExpressionTest.MyEnum.X",
Expressions.toString(
Expressions.constant(MyEnum.X)));
// array of enum
assertEquals(
- "new net.hydromatic.linq4j.test.ExpressionTest.MyEnum[] {\n"
- + " net.hydromatic.linq4j.test.ExpressionTest.MyEnum.X,\n"
- + " net.hydromatic.linq4j.test.ExpressionTest.MyEnum.Y}",
+ "new org.apache.calcite.linq4j.test.ExpressionTest.MyEnum[] {\n"
+ + " org.apache.calcite.linq4j.test.ExpressionTest.MyEnum.X,\n"
+ + " org.apache.calcite.linq4j.test.ExpressionTest.MyEnum.Y}",
Expressions.toString(
Expressions.constant(new MyEnum[]{MyEnum.X, MyEnum.Y})));
@@ -542,23 +562,23 @@ public class ExpressionTest {
// automatically call constructor if it matches fields
assertEquals(
- "new net.hydromatic.linq4j.test.Linq4jTest.Employee[] {\n"
- + " new net.hydromatic.linq4j.test.Linq4jTest.Employee(\n"
- + " 100,\n"
- + " \"Fred\",\n"
- + " 10),\n"
- + " new net.hydromatic.linq4j.test.Linq4jTest.Employee(\n"
- + " 110,\n"
- + " \"Bill\",\n"
- + " 30),\n"
- + " new net.hydromatic.linq4j.test.Linq4jTest.Employee(\n"
- + " 120,\n"
- + " \"Eric\",\n"
- + " 10),\n"
- + " new net.hydromatic.linq4j.test.Linq4jTest.Employee(\n"
- + " 130,\n"
- + " \"Janet\",\n"
- + " 10)}",
+ "new org.apache.calcite.linq4j.test.Linq4jTest.Employee[] {\n"
+ + " new org.apache.calcite.linq4j.test.Linq4jTest.Employee(\n"
+ + " 100,\n"
+ + " \"Fred\",\n"
+ + " 10),\n"
+ + " new org.apache.calcite.linq4j.test.Linq4jTest.Employee(\n"
+ + " 110,\n"
+ + " \"Bill\",\n"
+ + " 30),\n"
+ + " new org.apache.calcite.linq4j.test.Linq4jTest.Employee(\n"
+ + " 120,\n"
+ + " \"Eric\",\n"
+ + " 10),\n"
+ + " new org.apache.calcite.linq4j.test.Linq4jTest.Employee(\n"
+ + " 130,\n"
+ + " \"Janet\",\n"
+ + " 10)}",
Expressions.toString(
Expressions.constant(Linq4jTest.emps)));
}
@@ -645,19 +665,19 @@ public class ExpressionTest {
.<Expression>emptyList())))))));
assertEquals(
"{\n"
- + " final java.util.List<String> baz = java.util.Arrays.asList(\"foo\", \"bar\");\n"
- + " new java.util.AbstractList<String>(){\n"
- + " public final String qux = \"xyzzy\";\n"
- + " public int size() {\n"
- + " return baz.size();\n"
- + " }\n"
- + "\n"
- + " public String get(int index) {\n"
- + " return ((String) baz.get(index)).toUpperCase();\n"
- + " }\n"
- + "\n"
- + " };\n"
- + "}\n",
+ + " final java.util.List<String> baz = java.util.Arrays.asList(\"foo\", \"bar\");\n"
+ + " new java.util.AbstractList<String>(){\n"
+ + " public final String qux = \"xyzzy\";\n"
+ + " public int size() {\n"
+ + " return baz.size();\n"
+ + " }\n"
+ + "\n"
+ + " public String get(int index) {\n"
+ + " return ((String) baz.get(index)).toUpperCase();\n"
+ + " }\n"
+ + "\n"
+ + " };\n"
+ + "}\n",
Expressions.toString(e));
}
@@ -682,12 +702,12 @@ public class ExpressionTest {
Expressions.preIncrementAssign(yDecl.parameter))));
assertEquals(
"{\n"
- + " int x = 10;\n"
- + " int y = 0;\n"
- + " while (x < 5) {\n"
- + " ++y;\n"
- + " }\n"
- + "}\n",
+ + " int x = 10;\n"
+ + " int y = 0;\n"
+ + " while (x < 5) {\n"
+ + " ++y;\n"
+ + " }\n"
+ + "}\n",
Expressions.toString(node));
}
@@ -707,21 +727,21 @@ public class ExpressionTest {
Expressions.call(
Expressions.constant("foo"),
"toUpperCase")),
- Expressions.catch_(cce_,
- Expressions.return_(null, Expressions.constant(null))),
- Expressions.catch_(re_,
- Expressions.throw_(
- Expressions.new_(IndexOutOfBoundsException.class))));
+ Expressions.catch_(cce_,
+ Expressions.return_(null, Expressions.constant(null))),
+ Expressions.catch_(re_,
+ Expressions.throw_(
+ Expressions.new_(IndexOutOfBoundsException.class))));
assertEquals(
"try {\n"
- + " return \"foo\".length();\n"
- + "} catch (final ClassCastException cce) {\n"
- + " return null;\n"
- + "} catch (RuntimeException re) {\n"
- + " throw new IndexOutOfBoundsException();\n"
- + "} finally {\n"
- + " \"foo\".toUpperCase();\n"
- + "}\n",
+ + " return \"foo\".length();\n"
+ + "} catch (final ClassCastException cce) {\n"
+ + " return null;\n"
+ + "} catch (RuntimeException re) {\n"
+ + " throw new IndexOutOfBoundsException();\n"
+ + "} finally {\n"
+ + " \"foo\".toUpperCase();\n"
+ + "}\n",
Expressions.toString(node));
}
@@ -733,24 +753,24 @@ public class ExpressionTest {
Node node =
Expressions.ifThen(
Expressions.constant(true),
- Expressions.tryFinally(
- Expressions.block(
- Expressions.return_(null,
+ Expressions.tryFinally(
+ Expressions.block(
+ Expressions.return_(null,
+ Expressions.call(
+ Expressions.constant("foo"),
+ "length"))),
+ Expressions.statement(
Expressions.call(
Expressions.constant("foo"),
- "length"))),
- Expressions.statement(
- Expressions.call(
- Expressions.constant("foo"),
- "toUpperCase"))));
+ "toUpperCase"))));
assertEquals(
"if (true) {\n"
- + " try {\n"
- + " return \"foo\".length();\n"
- + " } finally {\n"
- + " \"foo\".toUpperCase();\n"
- + " }\n"
- + "}\n",
+ + " try {\n"
+ + " return \"foo\".length();\n"
+ + " } finally {\n"
+ + " \"foo\".toUpperCase();\n"
+ + " }\n"
+ + "}\n",
Expressions.toString(node));
}
@@ -771,12 +791,12 @@ public class ExpressionTest {
Expressions.call(re_, "toString"))));
assertEquals(
"try {\n"
- + " return \"foo\".length();\n"
- + "} catch (final ClassCastException cce) {\n"
- + " return null;\n"
- + "} catch (RuntimeException re) {\n"
- + " return re.toString();\n"
- + "}\n",
+ + " return \"foo\".length();\n"
+ + "} catch (final ClassCastException cce) {\n"
+ + " return null;\n"
+ + "} catch (RuntimeException re) {\n"
+ + " return re.toString();\n"
+ + "}\n",
Expressions.toString(node));
}
@@ -837,18 +857,18 @@ public class ExpressionTest {
checkBlockBuilder(
false,
"{\n"
- + " final int three = 1 + 2;\n"
- + " final int six = three * 2;\n"
- + " final int nine = three * three;\n"
- + " final int eighteen = three + six + nine;\n"
- + " return eighteen;\n"
- + "}\n");
+ + " final int three = 1 + 2;\n"
+ + " final int six = three * 2;\n"
+ + " final int nine = three * three;\n"
+ + " final int eighteen = three + six + nine;\n"
+ + " return eighteen;\n"
+ + "}\n");
checkBlockBuilder(
true,
"{\n"
- + " final int three = 1 + 2;\n"
- + " return three + three * 2 + three * three;\n"
- + "}\n");
+ + " final int three = 1 + 2;\n"
+ + " return three + three * 2 + three * three;\n"
+ + "}\n");
}
public void checkBlockBuilder(boolean optimizing, String expected) {
@@ -906,9 +926,9 @@ public class ExpressionTest {
BlockStatement expression = statements.toBlock();
assertEquals(
"{\n"
- + " return new java.util.TreeSet(\n"
- + " (java.util.Comparator) null).add(null);\n"
- + "}\n",
+ + " return new java.util.TreeSet(\n"
+ + " (java.util.Comparator) null).add(null);\n"
+ + "}\n",
Expressions.toString(expression));
expression.accept(new Visitor());
}
@@ -952,11 +972,11 @@ public class ExpressionTest {
BlockStatement expression = builder0.toBlock();
assertEquals(
"{\n"
- + " final int _b = 1 + 2;\n"
- + " final int _c = 1 + 3;\n"
- + " final int _d = 1 + 4;\n"
- + " net.hydromatic.linq4j.test.ExpressionTest.bar(1, _b, _c, _d, net.hydromatic.linq4j.test.ExpressionTest.foo(_c));\n"
- + "}\n",
+ + " final int _b = 1 + 2;\n"
+ + " final int _c = 1 + 3;\n"
+ + " final int _d = 1 + 4;\n"
+ + " org.apache.calcite.linq4j.test.ExpressionTest.bar(1, _b, _c, _d, org.apache.calcite.linq4j.test.ExpressionTest.foo(_c));\n"
+ + "}\n",
Expressions.toString(expression));
expression.accept(new Visitor());
}
@@ -970,36 +990,36 @@ public class ExpressionTest {
(float) 5, (double) 6, (char) 7, true, "string", null
},
new AllType(true, (byte) 100, (char) 101, (short) 102, 103,
- (long) 104, (float) 105, (double) 106, new BigDecimal(107),
- new BigInteger("108"), "109", null)
+ (long) 104, (float) 105, (double) 106, new BigDecimal(107),
+ new BigInteger("108"), "109", null)
});
assertEquals(
"new Object[] {\n"
- + " 1,\n"
- + " new Object[] {\n"
- + " (byte)1,\n"
- + " (short)2,\n"
- + " 3,\n"
- + " 4L,\n"
- + " 5.0F,\n"
- + " 6.0D,\n"
- + " (char)7,\n"
- + " true,\n"
- + " \"string\",\n"
- + " null},\n"
- + " new net.hydromatic.linq4j.test.ExpressionTest.AllType(\n"
- + " true,\n"
- + " (byte)100,\n"
- + " (char)101,\n"
- + " (short)102,\n"
- + " 103,\n"
- + " 104L,\n"
- + " 105.0F,\n"
- + " 106.0D,\n"
- + " new java.math.BigDecimal(107L),\n"
- + " new java.math.BigInteger(\"108\"),\n"
- + " \"109\",\n"
- + " null)}",
+ + " 1,\n"
+ + " new Object[] {\n"
+ + " (byte)1,\n"
+ + " (short)2,\n"
+ + " 3,\n"
+ + " 4L,\n"
+ + " 5.0F,\n"
+ + " 6.0D,\n"
+ + " (char)7,\n"
+ + " true,\n"
+ + " \"string\",\n"
+ + " null},\n"
+ + " new org.apache.calcite.linq4j.test.ExpressionTest.AllType(\n"
+ + " true,\n"
+ + " (byte)100,\n"
+ + " (char)101,\n"
+ + " (short)102,\n"
+ + " 103,\n"
+ + " 104L,\n"
+ + " 105.0F,\n"
+ + " 106.0D,\n"
+ + " new java.math.BigDecimal(107L),\n"
+ + " new java.math.BigInteger(\"108\"),\n"
+ + " \"109\",\n"
+ + " null)}",
constant.toString());
constant.accept(new Visitor());
}
@@ -1029,12 +1049,12 @@ public class ExpressionTest {
Expressions.parameter(int.class, "i"))));
assertEquals(
"new Object(){\n"
- + " public final String foo = \"bar\";\n"
- + " public static class MyClass {\n"
- + " int x = 0;\n"
- + " }\n"
- + " int i;\n"
- + "}",
+ + " public final String foo = \"bar\";\n"
+ + " public static class MyClass {\n"
+ + " int x = 0;\n"
+ + " }\n"
+ + " int i;\n"
+ + "}",
Expressions.toString(newExpression));
newExpression.accept(new Visitor());
}
@@ -1042,10 +1062,10 @@ public class ExpressionTest {
@Test public void testReturn() {
assertEquals(
"if (true) {\n"
- + " return;\n"
- + "} else {\n"
- + " return 1;\n"
- + "}\n",
+ + " return;\n"
+ + "} else {\n"
+ + " return 1;\n"
+ + "}\n",
Expressions.toString(
Expressions.ifThenElse(
Expressions.constant(true),
@@ -1056,12 +1076,12 @@ public class ExpressionTest {
@Test public void testIfElseIfElse() {
assertEquals(
"if (true) {\n"
- + " return;\n"
- + "} else if (false) {\n"
- + " return;\n"
- + "} else {\n"
- + " return 1;\n"
- + "}\n",
+ + " return;\n"
+ + "} else if (false) {\n"
+ + " return;\n"
+ + "} else {\n"
+ + " return 1;\n"
+ + "}\n",
Expressions.toString(
Expressions.ifThenElse(
Expressions.constant(true),
@@ -1115,10 +1135,10 @@ public class ExpressionTest {
builder.add(Expressions.return_(null, v6));
assertEquals(
"{\n"
- + " final Short v = (Short) ((Object[]) p)[4];\n"
- + " return (Number) v == null ? (Boolean) null : ("
- + "(Number) v).intValue() == 1997;\n"
- + "}\n",
+ + " final Short v = (Short) ((Object[]) p)[4];\n"
+ + " return (Number) v == null ? (Boolean) null : ("
+ + "(Number) v).intValue() == 1997;\n"
+ + "}\n",
Expressions.toString(builder.toBlock()));
}
@@ -1140,10 +1160,10 @@ public class ExpressionTest {
i_)))));
assertEquals(
"{\n"
- + " for (int i = 0; i < 10; i++) {\n"
- + " System.out.println(i);\n"
- + " }\n"
- + "}\n",
+ + " for (int i = 0; i < 10; i++) {\n"
+ + " System.out.println(i);\n"
+ + " }\n"
+ + "}\n",
Expressions.toString(builder.toBlock()));
}
@@ -1168,12 +1188,12 @@ public class ExpressionTest {
Expressions.break_(null)))));
assertEquals(
"{\n"
- + " for (int i = 0, j = 10; ; ) {\n"
- + " if (++i < --j) {\n"
- + " break;\n"
- + " }\n"
- + " }\n"
- + "}\n",
+ + " for (int i = 0, j = 10; ; ) {\n"
+ + " if (++i < --j) {\n"
+ + " break;\n"
+ + " }\n"
+ + " }\n"
+ + "}\n",
Expressions.toString(builder.toBlock()));
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/test/InlinerTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/InlinerTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/InlinerTest.java
index d3cf084..79e2f7d 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/InlinerTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/InlinerTest.java
@@ -14,9 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.linq4j.test;
+package org.apache.calcite.linq4j.test;
-import net.hydromatic.linq4j.expressions.*;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.DeclarationStatement;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.ExpressionType;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
@@ -24,7 +29,9 @@ import org.junit.Test;
import java.lang.reflect.Modifier;
-import static net.hydromatic.linq4j.test.BlockBuilderBase.*;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.ONE;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.TRUE;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.TWO;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@@ -78,9 +85,9 @@ public class InlinerTest {
Expressions.add(decl.parameter, decl.parameter)));
assertEquals(
"{\n"
- + " final int x = p1 - p2;\n"
- + " return x + x;\n"
- + "}\n",
+ + " final int x = p1 - p2;\n"
+ + " return x + x;\n"
+ + "}\n",
b.toBlock().toString());
}
@@ -102,25 +109,25 @@ public class InlinerTest {
builder.add(Expressions.return_(null, v));
assertEquals(
"{\n"
- + " int t;\n"
- + " return (t = 1) != a ? t : c;\n"
- + "}\n",
+ + " int t;\n"
+ + " return (t = 1) != a ? t : c;\n"
+ + "}\n",
Expressions.toString(builder.toBlock()));
}
@Test public void testAssignInConditionOptimizedOut() {
checkAssignInConditionOptimizedOut(Modifier.FINAL,
"{\n"
- + " return 1 != a ? b : c;\n"
- + "}\n");
+ + " return 1 != a ? b : c;\n"
+ + "}\n");
}
@Test public void testAssignInConditionNotOptimizedWithoutFinal() {
checkAssignInConditionOptimizedOut(0,
"{\n"
- + " int t;\n"
- + " return (t = 1) != a ? b : c;\n"
- + "}\n");
+ + " int t;\n"
+ + " return (t = 1) != a ? b : c;\n"
+ + "}\n");
}
void checkAssignInConditionOptimizedOut(int modifiers, String s) {
@@ -162,9 +169,9 @@ public class InlinerTest {
builder.add(Expressions.return_(null, v));
assertEquals(
"{\n"
- + " int t = 2;\n"
- + " return (t = 1) != a ? t : c;\n"
- + "}\n",
+ + " int t = 2;\n"
+ + " return (t = 1) != a ? t : c;\n"
+ + "}\n",
Expressions.toString(builder.toBlock()));
}
@@ -183,8 +190,8 @@ public class InlinerTest {
builder.add(Expressions.return_(null, Expressions.condition(b, t, TWO)));
assertEquals(
"{\n"
- + " return u + v;\n"
- + "}\n",
+ + " return u + v;\n"
+ + "}\n",
Expressions.toString(builder.toBlock()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java
index 91bd886..fd044cb 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jSuite.java
@@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.linq4j.test;
+package org.apache.calcite.linq4j.test;
-import net.hydromatic.linq4j.expressions.TypeTest;
-import net.hydromatic.linq4j.function.FunctionTest;
+import org.apache.calcite.linq4j.function.FunctionTest;
+import org.apache.calcite.linq4j.tree.TypeTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
index b9ce961..5c92e9e 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
@@ -14,20 +14,53 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.linq4j.test;
-
-import net.hydromatic.linq4j.*;
-import net.hydromatic.linq4j.expressions.*;
-import net.hydromatic.linq4j.function.*;
+package org.apache.calcite.linq4j.test;
+
+import org.apache.calcite.linq4j.AbstractEnumerable;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.EnumerableDefaults;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.linq4j.ExtendedEnumerable;
+import org.apache.calcite.linq4j.Grouping;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.Lookup;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.linq4j.QueryableDefaults;
+import org.apache.calcite.linq4j.function.EqualityComparer;
+import org.apache.calcite.linq4j.function.Function0;
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.linq4j.function.Function2;
+import org.apache.calcite.linq4j.function.Functions;
+import org.apache.calcite.linq4j.function.IntegerFunction1;
+import org.apache.calcite.linq4j.function.Predicate1;
+import org.apache.calcite.linq4j.function.Predicate2;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
import com.example.Linq4jExample;
import org.junit.Test;
-import java.util.*;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.TreeSet;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Tests for LINQ4J.
@@ -369,16 +402,16 @@ public class Linq4jTest {
@Test public void testContainsWithEqualityComparer() {
EqualityComparer<Employee> compareByEmpno =
- new EqualityComparer<Employee>() {
- public boolean equal(Employee e1, Employee e2) {
- return e1 != null && e2 != null
- && e1.empno == e2.empno;
- }
+ new EqualityComparer<Employee>() {
+ public boolean equal(Employee e1, Employee e2) {
+ return e1 != null && e2 != null
+ && e1.empno == e2.empno;
+ }
- public int hashCode(Employee t) {
- return t == null ? 0x789d : t.hashCode();
- }
- };
+ public int hashCode(Employee t) {
+ return t == null ? 0x789d : t.hashCode();
+ }
+ };
Employee e = emps[1];
Employee employeeClone = new Employee(e.empno, e.name, e.deptno);
@@ -386,11 +419,11 @@ public class Linq4jTest {
assertEquals(e, employeeClone);
assertTrue(Linq4j.asEnumerable(emps)
- .contains(e, compareByEmpno));
+ .contains(e, compareByEmpno));
assertTrue(Linq4j.asEnumerable(emps)
- .contains(employeeClone, compareByEmpno));
+ .contains(employeeClone, compareByEmpno));
assertFalse(Linq4j.asEnumerable(emps)
- .contains(employeeOther, compareByEmpno));
+ .contains(employeeOther, compareByEmpno));
}
@@ -539,7 +572,7 @@ public class Linq4jTest {
}
assertEquals(
"Fred: [Employee(name: Fred, deptno:10), Employee(name: Bill, deptno:30), Employee(name: Eric, deptno:10)]\n"
- + "Janet: [Employee(name: Janet, deptno:10)]\n",
+ + "Janet: [Employee(name: Janet, deptno:10)]\n",
buf.toString());
}
@@ -818,8 +851,8 @@ public class Linq4jTest {
.toString();
assertEquals(
"[[Fred, Eric, Janet] work(s) in Sales, "
- + "[] work(s) in HR, "
- + "[Bill] work(s) in Marketing]",
+ + "[] work(s) in HR, "
+ + "[Bill] work(s) in Marketing]",
s);
}
@@ -844,9 +877,9 @@ public class Linq4jTest {
.toString();
assertEquals(
"[Bill works in Marketing, "
- + "Eric works in Sales, "
- + "Fred works in Sales, "
- + "Janet works in Sales]",
+ + "Eric works in Sales, "
+ + "Fred works in Sales, "
+ + "Janet works in Sales]",
s);
}
@@ -873,10 +906,10 @@ public class Linq4jTest {
.toString();
assertEquals(
"[Bill works in Marketing, "
- + "Cedric works in null, "
- + "Eric works in Sales, "
- + "Fred works in Sales, "
- + "Janet works in Sales]",
+ + "Cedric works in null, "
+ + "Eric works in Sales, "
+ + "Fred works in Sales, "
+ + "Janet works in Sales]",
s);
}
@@ -903,10 +936,10 @@ public class Linq4jTest {
.toString();
assertEquals(
"[Bill works in Marketing, "
- + "Eric works in Sales, "
- + "Fred works in Sales, "
- + "Janet works in Sales, "
- + "null works in HR]",
+ + "Eric works in Sales, "
+ + "Fred works in Sales, "
+ + "Janet works in Sales, "
+ + "null works in HR]",
s);
}
@@ -933,11 +966,11 @@ public class Linq4jTest {
.toString();
assertEquals(
"[Bill works in Marketing, "
- + "Cedric works in null, "
- + "Eric works in Sales, "
- + "Fred works in Sales, "
- + "Janet works in Sales, "
- + "null works in HR]",
+ + "Cedric works in null, "
+ + "Eric works in Sales, "
+ + "Fred works in Sales, "
+ + "Janet works in Sales, "
+ + "null works in HR]",
s);
}
@@ -1173,7 +1206,7 @@ public class Linq4jTest {
public boolean apply(Department v1, Integer v2) {
// Make sure we're passed the correct indices
assertEquals(
- "Invalid index passed to function", index++, (int) v2);
+ "Invalid index passed to function", index++, (int) v2);
return 20 != v1.deptno;
}
}).toList();
@@ -1272,7 +1305,7 @@ public class Linq4jTest {
new Predicate2<Department, Integer>() {
public boolean apply(Department v1, Integer v2) {
return v1.name.equals("Sales")
- || v2 == 1;
+ || v2 == 1;
}
}).count());
@@ -1301,7 +1334,7 @@ public class Linq4jTest {
new Predicate2<Department, Integer>() {
public boolean apply(Department v1, Integer v2) {
return v1.name.equals("Sales")
- || v2 == 1;
+ || v2 == 1;
}
})).count());
}
@@ -1310,9 +1343,9 @@ public class Linq4jTest {
// Note: sort is stable. Records occur Fred, Eric, Janet in input.
assertEquals(
"[Employee(name: Fred, deptno:10),"
- + " Employee(name: Eric, deptno:10),"
- + " Employee(name: Janet, deptno:10),"
- + " Employee(name: Bill, deptno:30)]",
+ + " Employee(name: Eric, deptno:10),"
+ + " Employee(name: Janet, deptno:10),"
+ + " Employee(name: Bill, deptno:30)]",
Linq4j.asEnumerable(emps).orderBy(EMP_DEPTNO_SELECTOR)
.toList().toString());
}
@@ -1320,9 +1353,9 @@ public class Linq4jTest {
@Test public void testOrderByComparator() {
assertEquals(
"[Employee(name: Bill, deptno:30),"
- + " Employee(name: Eric, deptno:10),"
- + " Employee(name: Fred, deptno:10),"
- + " Employee(name: Janet, deptno:10)]",
+ + " Employee(name: Eric, deptno:10),"
+ + " Employee(name: Fred, deptno:10),"
+ + " Employee(name: Janet, deptno:10)]",
Linq4j.asEnumerable(emps)
.orderBy(EMP_NAME_SELECTOR)
.orderBy(
@@ -1334,9 +1367,9 @@ public class Linq4jTest {
// OrderBy in series works because sort is stable.
assertEquals(
"[Employee(name: Eric, deptno:10),"
- + " Employee(name: Fred, deptno:10),"
- + " Employee(name: Janet, deptno:10),"
- + " Employee(name: Bill, deptno:30)]",
+ + " Employee(name: Fred, deptno:10),"
+ + " Employee(name: Janet, deptno:10),"
+ + " Employee(name: Bill, deptno:30)]",
Linq4j.asEnumerable(emps)
.orderBy(EMP_NAME_SELECTOR)
.orderBy(EMP_DEPTNO_SELECTOR)
@@ -1346,9 +1379,9 @@ public class Linq4jTest {
@Test public void testOrderByDescending() {
assertEquals(
"[Employee(name: Janet, deptno:10),"
- + " Employee(name: Fred, deptno:10),"
- + " Employee(name: Eric, deptno:10),"
- + " Employee(name: Bill, deptno:30)]",
+ + " Employee(name: Fred, deptno:10),"
+ + " Employee(name: Eric, deptno:10),"
+ + " Employee(name: Bill, deptno:30)]",
Linq4j.asEnumerable(emps)
.orderByDescending(EMP_NAME_SELECTOR)
.toList().toString());
@@ -1357,9 +1390,9 @@ public class Linq4jTest {
@Test public void testReverse() {
assertEquals(
"[Employee(name: Janet, deptno:10),"
- + " Employee(name: Eric, deptno:10),"
- + " Employee(name: Bill, deptno:30),"
- + " Employee(name: Fred, deptno:10)]",
+ + " Employee(name: Eric, deptno:10),"
+ + " Employee(name: Bill, deptno:30),"
+ + " Employee(name: Fred, deptno:10)]",
Linq4j.asEnumerable(emps)
.reverse()
.toList()
@@ -1430,8 +1463,7 @@ public class Linq4jTest {
return "Employee(name: " + name + ", deptno:" + deptno + ")";
}
- @Override
- public int hashCode() {
+ @Override public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + deptno;
@@ -1440,8 +1472,7 @@ public class Linq4jTest {
return result;
}
- @Override
- public boolean equals(Object obj) {
+ @Override public boolean equals(Object obj) {
if (this == obj) {
return true;
}
@@ -1483,9 +1514,9 @@ public class Linq4jTest {
public String toString() {
return "Department(name: " + name
- + ", deptno:" + deptno
- + ", employees: " + employees
- + ")";
+ + ", deptno:" + deptno
+ + ", employees: " + employees
+ + ")";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/test/OptimizerTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/OptimizerTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/OptimizerTest.java
index ab2b7b0..dd0d82d 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/OptimizerTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/OptimizerTest.java
@@ -14,23 +14,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.linq4j.test;
+package org.apache.calcite.linq4j.test;
-import net.hydromatic.linq4j.Linq4j;
-import net.hydromatic.linq4j.expressions.*;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.tree.ConstantExpression;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
import org.junit.Test;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import static net.hydromatic.linq4j.test.BlockBuilderBase.*;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.FALSE;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.FOUR;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.NULL;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.NULL_INTEGER;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.ONE;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.THREE;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.TRUE;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.TRUE_B;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.TWO;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.bool;
+import static org.apache.calcite.linq4j.test.BlockBuilderBase.optimize;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
/**
- * Unit test for {@link net.hydromatic.linq4j.expressions.BlockBuilder}
+ * Unit test for {@link org.apache.calcite.linq4j.tree.BlockBuilder}
* optimization capabilities.
*/
public class OptimizerTest {
@@ -110,7 +124,7 @@ public class OptimizerTest {
optimize(Expressions.condition(
Expressions.parameter(boolean.class, "a"),
TRUE_B, Expressions.call(Boolean.class, "valueOf",
- Expressions.parameter(boolean.class, "b")))));
+ Expressions.parameter(boolean.class, "b")))));
}
@Test public void testOptimizeTernaryABtrue() {
@@ -141,8 +155,8 @@ public class OptimizerTest {
// (v ? (Integer) null : inp0_) == null
assertEquals("{\n return v || inp0_ == null;\n}\n",
optimize(Expressions.equal(Expressions.condition(
- Expressions.parameter(boolean.class, "v"),
- NULL_INTEGER, Expressions.parameter(Integer.class, "inp0_")),
+ Expressions.parameter(boolean.class, "v"),
+ NULL_INTEGER, Expressions.parameter(Integer.class, "inp0_")),
NULL)));
}
@@ -150,8 +164,8 @@ public class OptimizerTest {
// (v ? inp0_ : (Integer) null) == null
assertEquals("{\n return !v || inp0_ == null;\n}\n",
optimize(Expressions.equal(Expressions.condition(
- Expressions.parameter(boolean.class, "v"),
- Expressions.parameter(Integer.class, "inp0_"), NULL_INTEGER),
+ Expressions.parameter(boolean.class, "v"),
+ Expressions.parameter(Integer.class, "inp0_"), NULL_INTEGER),
NULL)));
}
@@ -175,8 +189,8 @@ public class OptimizerTest {
// (v ? (Integer) null : inp0_) != null
assertEquals("{\n return !(v || inp0_ == null);\n}\n",
optimize(Expressions.notEqual(Expressions.condition(
- Expressions.parameter(boolean.class, "v"),
- NULL_INTEGER, Expressions.parameter(Integer.class, "inp0_")),
+ Expressions.parameter(boolean.class, "v"),
+ NULL_INTEGER, Expressions.parameter(Integer.class, "inp0_")),
NULL)));
}
@@ -184,8 +198,8 @@ public class OptimizerTest {
// (v ? inp0_ : (Integer) null) != null
assertEquals("{\n return !(!v || inp0_ == null);\n}\n",
optimize(Expressions.notEqual(Expressions.condition(
- Expressions.parameter(boolean.class, "v"),
- Expressions.parameter(Integer.class, "inp0_"), NULL_INTEGER),
+ Expressions.parameter(boolean.class, "v"),
+ Expressions.parameter(Integer.class, "inp0_"), NULL_INTEGER),
NULL)));
}
@@ -487,12 +501,12 @@ public class OptimizerTest {
Expression bool = Expressions.parameter(boolean.class, "bool");
assertEquals(
"{\n"
- + " if (bool) {\n"
- + " return 1;\n"
- + " } else {\n"
- + " return 2;\n"
- + " }\n"
- + "}\n",
+ + " if (bool) {\n"
+ + " return 1;\n"
+ + " } else {\n"
+ + " return 2;\n"
+ + " }\n"
+ + "}\n",
optimize(
Expressions.ifThenElse(bool,
Expressions.return_(null, ONE),
@@ -505,12 +519,12 @@ public class OptimizerTest {
Expression bool = Expressions.parameter(boolean.class, "bool");
assertEquals(
"{\n"
- + " if (bool) {\n"
- + " return 1;\n"
- + " } else {\n"
- + " return 2;\n"
- + " }\n"
- + "}\n",
+ + " if (bool) {\n"
+ + " return 1;\n"
+ + " } else {\n"
+ + " return 2;\n"
+ + " }\n"
+ + "}\n",
optimize(
Expressions.ifThenElse(bool,
Expressions.return_(null, ONE),
@@ -524,10 +538,10 @@ public class OptimizerTest {
Expression bool = Expressions.parameter(boolean.class, "bool");
assertEquals(
"{\n"
- + " if (bool) {\n"
- + " return 1;\n"
- + " }\n"
- + "}\n",
+ + " if (bool) {\n"
+ + " return 1;\n"
+ + " }\n"
+ + "}\n",
optimize(
Expressions.ifThenElse(bool,
Expressions.return_(null, ONE),
@@ -540,12 +554,12 @@ public class OptimizerTest {
Expression bool = Expressions.parameter(boolean.class, "bool");
assertEquals(
"{\n"
- + " if (bool) {\n"
- + " return 1;\n"
- + " } else {\n"
- + " return 3;\n"
- + " }\n"
- + "}\n",
+ + " if (bool) {\n"
+ + " return 1;\n"
+ + " } else {\n"
+ + " return 3;\n"
+ + " }\n"
+ + "}\n",
optimize(
Expressions.ifThenElse(bool,
Expressions.return_(null, ONE),
@@ -559,12 +573,12 @@ public class OptimizerTest {
Expression bool = Expressions.parameter(boolean.class, "bool");
assertEquals(
"{\n"
- + " if (bool) {\n"
- + " return 1;\n"
- + " } else {\n"
- + " return 4;\n"
- + " }\n"
- + "}\n",
+ + " if (bool) {\n"
+ + " return 1;\n"
+ + " } else {\n"
+ + " return 4;\n"
+ + " }\n"
+ + "}\n",
optimize(
Expressions.ifThenElse(bool,
Expressions.return_(null, ONE),
@@ -697,8 +711,7 @@ public class OptimizerTest {
Expressions.field(null, System.class, "out"),
"println",
x_)))),
- equalTo(
- "{\n"
+ equalTo("{\n"
+ " long x = 0L;\n"
+ " if (System.nanoTime() > 0L) {\n"
+ " x = System.currentTimeMillis();\n"
@@ -727,8 +740,7 @@ public class OptimizerTest {
Expressions.ifThen(
Expressions.greaterThan(Expressions.call(mT), zero),
Expressions.statement(Expressions.assign(x_, y_))))),
- equalTo(
- "{\n"
+ equalTo("{\n"
+ " long x = 0L;\n"
+ " if (System.currentTimeMillis() > 0L) {\n"
+ " x = System.currentTimeMillis();\n"
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/test/PrimitiveTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/PrimitiveTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/PrimitiveTest.java
index b341b5c..841fa40 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/PrimitiveTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/PrimitiveTest.java
@@ -14,16 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.linq4j.test;
+package org.apache.calcite.linq4j.test;
-import net.hydromatic.linq4j.expressions.Primitive;
+import org.apache.calcite.linq4j.tree.Primitive;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Unit test for {@link Primitive}.
@@ -118,7 +124,8 @@ public class PrimitiveTest {
}
}
- /** Test for {@link Primitive#send(net.hydromatic.linq4j.expressions.Primitive.Source, net.hydromatic.linq4j.expressions.Primitive.Sink)}. */
+ /** Test for
+ * {@link Primitive#send(org.apache.calcite.linq4j.tree.Primitive.Source, org.apache.calcite.linq4j.tree.Primitive.Sink)}. */
@Test public void testSendSource() {
final List<Object> list = new ArrayList<Object>();
for (Primitive primitive : Primitive.values()) {
@@ -216,18 +223,17 @@ public class PrimitiveTest {
}
});
}
- assertEquals(
- "[boolean, boolean, true, "
- + "byte, byte, 0, "
- + "char, char, \u0000, "
- + "short, short, 0, "
- + "int, int, 0, "
- + "long, long, 0, "
- + "float, float, 0.0, "
- + "double, double, 0.0, "
- + "class java.lang.Object, class java.lang.Object, 0, "
- + "class java.lang.Object, class java.lang.Object, 0]",
- list.toString());
+ assertThat(list.toString(),
+ equalTo("[boolean, boolean, true, "
+ + "byte, byte, 0, "
+ + "char, char, \u0000, "
+ + "short, short, 0, "
+ + "int, int, 0, "
+ + "long, long, 0, "
+ + "float, float, 0.0, "
+ + "double, double, 0.0, "
+ + "class java.lang.Object, class java.lang.Object, 0, "
+ + "class java.lang.Object, class java.lang.Object, 0]"));
}
/** Test for {@link Primitive#permute(Object, int[])}. */
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/test/package-info.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/package-info.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/package-info.java
index 2122b1e..9745b87 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/package-info.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/package-info.java
@@ -18,6 +18,6 @@
/**
* Core linq4j tests.
*/
-package net.hydromatic.linq4j.test;
+package org.apache.calcite.linq4j.test;
// End package-info.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/tree/TypeTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/tree/TypeTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/tree/TypeTest.java
index 8cd5c8f..42b3fd2 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/tree/TypeTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/tree/TypeTest.java
@@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.linq4j.expressions;
+package org.apache.calcite.linq4j.tree;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
/**
* Test for {@link Types#gcd}.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/linq4j/src/test/java/org/apache/calcite/linq4j/tree/package-info.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/tree/package-info.java b/linq4j/src/test/java/org/apache/calcite/linq4j/tree/package-info.java
index 2f94472..655a4f5 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/tree/package-info.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/tree/package-info.java
@@ -18,6 +18,6 @@
/**
* Tests for expressions.
*/
-package net.hydromatic.linq4j.expressions;
+package org.apache.calcite.linq4j.tree;
// End package-info.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/pom.xml
----------------------------------------------------------------------
diff --git a/mongodb/pom.xml b/mongodb/pom.xml
index 55e7009..11980cb 100644
--- a/mongodb/pom.xml
+++ b/mongodb/pom.xml
@@ -104,32 +104,13 @@ limitations under the License.
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
- <include>net/hydromatic/optiq/test/MongoAdapterTest.java</include>
+ <include>org/apache/calcite/test/MongoAdapterTest.java</include>
</includes>
<threadCount>6</threadCount>
<parallel>both</parallel>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>javacc-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>javacc</id>
- <goals>
- <goal>javacc</goal>
- </goals>
- <configuration>
- <includes>
- <include>**/CombinedParser.jj</include>
- </includes>
- <lookAhead>2</lookAhead>
- <isStatic>false</isStatic>
- </configuration>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoAggregate.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoAggregate.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoAggregate.java
index 7346d32..9a1744e 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoAggregate.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoAggregate.java
@@ -14,27 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
+package org.apache.calcite.adapter.mongodb;
-import net.hydromatic.optiq.util.BitSets;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.InvalidRelException;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.fun.SqlSumAggFunction;
+import org.apache.calcite.sql.fun.SqlSumEmptyIsZeroAggFunction;
+import org.apache.calcite.util.BitSets;
+import org.apache.calcite.util.Util;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelTraitSet;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
-import org.eigenbase.sql.fun.SqlSumAggFunction;
-import org.eigenbase.sql.fun.SqlSumEmptyIsZeroAggFunction;
-import org.eigenbase.util.Util;
-
-import java.util.*;
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
/**
- * Implementation of {@link AggregateRelBase} relational expression in MongoDB.
+ * Implementation of
+ * {@link org.apache.calcite.rel.core.Aggregate} relational expression
+ * in MongoDB.
*/
-public class MongoAggregateRel
- extends AggregateRelBase
+public class MongoAggregate
+ extends Aggregate
implements MongoRel {
- public MongoAggregateRel(
+ public MongoAggregate(
RelOptCluster cluster,
RelTraitSet traitSet,
RelNode child,
@@ -53,10 +61,10 @@ public class MongoAggregateRel
}
}
- @Override public AggregateRelBase copy(RelTraitSet traitSet, RelNode input,
+ @Override public Aggregate copy(RelTraitSet traitSet, RelNode input,
BitSet groupSet, List<AggregateCall> aggCalls) {
try {
- return new MongoAggregateRel(getCluster(), traitSet, input, groupSet,
+ return new MongoAggregate(getCluster(), traitSet, input, groupSet,
aggCalls);
} catch (InvalidRelException e) {
// Semantic error not possible. Must be a bug. Convert to
@@ -66,10 +74,10 @@ public class MongoAggregateRel
}
public void implement(Implementor implementor) {
- implementor.visitChild(0, getChild());
+ implementor.visitChild(0, getInput());
List<String> list = new ArrayList<String>();
final List<String> inNames =
- MongoRules.mongoFieldNames(getChild().getRowType());
+ MongoRules.mongoFieldNames(getInput().getRowType());
final List<String> outNames = MongoRules.mongoFieldNames(getRowType());
int i = 0;
if (groupSet.cardinality() == 1) {
@@ -97,8 +105,7 @@ public class MongoAggregateRel
fixups = new AbstractList<String>() {
@Override public String get(int index) {
final String outName = outNames.get(index);
- return MongoRules.maybeQuote(outName)
- + ": "
+ return MongoRules.maybeQuote(outName) + ": "
+ MongoRules.maybeQuote("$" + (index == 0 ? "_id" : outName));
}
@@ -130,7 +137,7 @@ public class MongoAggregateRel
}
}
- private String toMongo(Aggregation aggregation, List<String> inNames,
+ private String toMongo(SqlAggFunction aggregation, List<String> inNames,
List<Integer> args) {
if (aggregation == SqlStdOperatorTable.COUNT) {
if (args.size() == 0) {
@@ -161,4 +168,4 @@ public class MongoAggregateRel
}
}
-// End MongoAggregateRel.java
+// End MongoAggregate.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoEnumerator.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoEnumerator.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoEnumerator.java
index c2d028c..fdb7112 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoEnumerator.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoEnumerator.java
@@ -14,16 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
+package org.apache.calcite.adapter.mongodb;
-import net.hydromatic.linq4j.Enumerator;
-import net.hydromatic.linq4j.function.Function1;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.util.DateTimeUtil;
-import org.eigenbase.util14.DateTimeUtil;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
-import com.mongodb.*;
-
-import java.util.*;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
/** Enumerator that reads from a MongoDB collection. */
class MongoEnumerator implements Enumerator<Object> {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoFilter.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoFilter.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoFilter.java
index e73bc54..5f717d7 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoFilter.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoFilter.java
@@ -14,27 +14,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.util.JsonBuilder;
-import org.eigenbase.util.Pair;
+package org.apache.calcite.adapter.mongodb;
+
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptCost;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.JsonBuilder;
+import org.apache.calcite.util.Pair;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
/**
- * Implementation of a {@link org.eigenbase.rel.FilterRel} relational expression
- * in MongoDB.
+ * Implementation of a {@link org.apache.calcite.rel.core.Filter}
+ * relational expression in MongoDB.
*/
-public class MongoFilterRel
- extends FilterRelBase
- implements MongoRel {
- public MongoFilterRel(
+public class MongoFilter extends Filter implements MongoRel {
+ public MongoFilter(
RelOptCluster cluster,
RelTraitSet traitSet,
RelNode child,
@@ -44,18 +54,17 @@ public class MongoFilterRel
assert getConvention() == child.getConvention();
}
- @Override
- public RelOptCost computeSelfCost(RelOptPlanner planner) {
+ @Override public RelOptCost computeSelfCost(RelOptPlanner planner) {
return super.computeSelfCost(planner).multiplyBy(0.1);
}
- public MongoFilterRel copy(RelTraitSet traitSet, RelNode input,
+ public MongoFilter copy(RelTraitSet traitSet, RelNode input,
RexNode condition) {
- return new MongoFilterRel(getCluster(), traitSet, input, condition);
+ return new MongoFilter(getCluster(), traitSet, input, condition);
}
public void implement(Implementor implementor) {
- implementor.visitChild(0, getChild());
+ implementor.visitChild(0, getInput());
Translator translator =
new Translator(MongoRules.mongoFieldNames(getRowType()));
String match = translator.translateMatch(condition);
@@ -202,4 +211,4 @@ public class MongoFilterRel
}
}
-// End MongoFilterRel.java
+// End MongoFilter.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoMethod.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoMethod.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoMethod.java
index ec03fbe..470b203 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoMethod.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoMethod.java
@@ -14,14 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
+package org.apache.calcite.adapter.mongodb;
-import net.hydromatic.linq4j.expressions.Types;
+import org.apache.calcite.linq4j.tree.Types;
import com.google.common.collect.ImmutableMap;
import java.lang.reflect.Method;
-import java.util.*;
+import java.util.List;
/**
* Builtin methods in the MongoDB adapter.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoProject.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoProject.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoProject.java
index 0b1521a..9bbf512 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoProject.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoProject.java
@@ -14,34 +14,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
+package org.apache.calcite.adapter.mongodb;
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptCost;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.util.Pair;
-import org.eigenbase.util.Util;
-
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
/**
- * Implementation of {@link ProjectRel} relational expression in
- * MongoDB.
+ * Implementation of {@link org.apache.calcite.rel.core.Project}
+ * relational expression in MongoDB.
*/
-public class MongoProjectRel extends ProjectRelBase implements MongoRel {
- public MongoProjectRel(RelOptCluster cluster, RelTraitSet traitSet,
+public class MongoProject extends Project implements MongoRel {
+ public MongoProject(RelOptCluster cluster, RelTraitSet traitSet,
RelNode child, List<RexNode> exps, RelDataType rowType, int flags) {
super(cluster, traitSet, child, exps, rowType, flags);
assert getConvention() == MongoRel.CONVENTION;
assert getConvention() == child.getConvention();
}
- @Override public ProjectRelBase copy(RelTraitSet traitSet, RelNode input,
+ @Override public Project copy(RelTraitSet traitSet, RelNode input,
List<RexNode> exps, RelDataType rowType) {
- return new MongoProjectRel(getCluster(), traitSet, input, exps,
+ return new MongoProject(getCluster(), traitSet, input, exps,
rowType, flags);
}
@@ -50,12 +54,12 @@ public class MongoProjectRel extends ProjectRelBase implements MongoRel {
}
public void implement(Implementor implementor) {
- implementor.visitChild(0, getChild());
+ implementor.visitChild(0, getInput());
final MongoRules.RexToMongoTranslator translator =
new MongoRules.RexToMongoTranslator(
(JavaTypeFactory) getCluster().getTypeFactory(),
- MongoRules.mongoFieldNames(getChild().getRowType()));
+ MongoRules.mongoFieldNames(getInput().getRowType()));
final List<String> items = new ArrayList<String>();
for (Pair<RexNode, String> pair : getNamedProjects()) {
final String name = pair.right;
@@ -71,4 +75,4 @@ public class MongoProjectRel extends ProjectRelBase implements MongoRel {
}
}
-// End MongoProjectRel.java
+// End MongoProject.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRel.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRel.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRel.java
index 272123d..c05c965 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRel.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRel.java
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
+package org.apache.calcite.adapter.mongodb;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.Convention;
-import org.eigenbase.relopt.RelOptTable;
-import org.eigenbase.util.Pair;
+import org.apache.calcite.plan.Convention;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.Pair;
import java.util.ArrayList;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
index 1b4b29e..88a45db 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
@@ -14,25 +14,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
-
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-import net.hydromatic.optiq.rules.java.RexImpTable;
-import net.hydromatic.optiq.rules.java.RexToLixTranslator;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.rel.convert.ConverterRule;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.rex.*;
-import org.eigenbase.sql.SqlKind;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
-import org.eigenbase.sql.type.SqlTypeName;
-import org.eigenbase.sql.validate.SqlValidatorUtil;
-import org.eigenbase.trace.EigenbaseTrace;
-import org.eigenbase.util.Bug;
-
-import java.util.*;
+package org.apache.calcite.adapter.mongodb;
+
+import org.apache.calcite.adapter.enumerable.RexImpTable;
+import org.apache.calcite.adapter.enumerable.RexToLixTranslator;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.plan.Convention;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelTrait;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.InvalidRelException;
+import org.apache.calcite.rel.RelCollationImpl;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.convert.ConverterRule;
+import org.apache.calcite.rel.core.Sort;
+import org.apache.calcite.rel.logical.LogicalAggregate;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
+import org.apache.calcite.util.Bug;
+import org.apache.calcite.util.trace.CalciteTrace;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.List;
import java.util.logging.Logger;
/**
@@ -43,7 +57,7 @@ import java.util.logging.Logger;
public class MongoRules {
private MongoRules() {}
- protected static final Logger LOGGER = EigenbaseTrace.getPlannerTracer();
+ protected static final Logger LOGGER = CalciteTrace.getPlannerTracer();
public static final RelOptRule[] RULES = {
MongoSortRule.INSTANCE,
@@ -185,90 +199,90 @@ public class MongoRules {
}
/**
- * Rule to convert a {@link org.eigenbase.rel.SortRel} to a
- * {@link MongoSortRel}.
+ * Rule to convert a {@link org.apache.calcite.rel.core.Sort} to a
+ * {@link MongoSort}.
*/
private static class MongoSortRule extends MongoConverterRule {
public static final MongoSortRule INSTANCE = new MongoSortRule();
private MongoSortRule() {
- super(SortRel.class, Convention.NONE, MongoRel.CONVENTION,
+ super(Sort.class, Convention.NONE, MongoRel.CONVENTION,
"MongoSortRule");
}
public RelNode convert(RelNode rel) {
- final SortRel sort = (SortRel) rel;
+ final Sort sort = (Sort) rel;
final RelTraitSet traitSet =
sort.getTraitSet().replace(out)
.replace(sort.getCollation());
- return new MongoSortRel(rel.getCluster(), traitSet,
- convert(sort.getChild(), traitSet.replace(RelCollationImpl.EMPTY)),
+ return new MongoSort(rel.getCluster(), traitSet,
+ convert(sort.getInput(), traitSet.replace(RelCollationImpl.EMPTY)),
sort.getCollation(), sort.offset, sort.fetch);
}
}
/**
- * Rule to convert a {@link org.eigenbase.rel.FilterRel} to a
- * {@link MongoFilterRel}.
+ * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalFilter} to a
+ * {@link MongoFilter}.
*/
private static class MongoFilterRule extends MongoConverterRule {
private static final MongoFilterRule INSTANCE = new MongoFilterRule();
private MongoFilterRule() {
- super(FilterRel.class, Convention.NONE, MongoRel.CONVENTION,
+ super(LogicalFilter.class, Convention.NONE, MongoRel.CONVENTION,
"MongoFilterRule");
}
public RelNode convert(RelNode rel) {
- final FilterRel filter = (FilterRel) rel;
+ final LogicalFilter filter = (LogicalFilter) rel;
final RelTraitSet traitSet = filter.getTraitSet().replace(out);
- return new MongoFilterRel(
+ return new MongoFilter(
rel.getCluster(),
traitSet,
- convert(filter.getChild(), traitSet),
+ convert(filter.getInput(), traitSet),
filter.getCondition());
}
}
/**
- * Rule to convert a {@link org.eigenbase.rel.ProjectRel} to a
- * {@link MongoProjectRel}.
+ * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalProject}
+ * to a {@link MongoProject}.
*/
private static class MongoProjectRule extends MongoConverterRule {
private static final MongoProjectRule INSTANCE = new MongoProjectRule();
private MongoProjectRule() {
- super(ProjectRel.class, Convention.NONE, MongoRel.CONVENTION,
+ super(LogicalProject.class, Convention.NONE, MongoRel.CONVENTION,
"MongoProjectRule");
}
public RelNode convert(RelNode rel) {
- final ProjectRel project = (ProjectRel) rel;
+ final LogicalProject project = (LogicalProject) rel;
final RelTraitSet traitSet = project.getTraitSet().replace(out);
- return new MongoProjectRel(project.getCluster(), traitSet,
- convert(project.getChild(), traitSet), project.getProjects(),
- project.getRowType(), ProjectRel.Flags.BOXED);
+ return new MongoProject(project.getCluster(), traitSet,
+ convert(project.getInput(), traitSet), project.getProjects(),
+ project.getRowType(), LogicalProject.Flags.BOXED);
}
}
/*
/**
- * Rule to convert a {@link CalcRel} to an
+ * Rule to convert a {@link LogicalCalc} to an
* {@link MongoCalcRel}.
o/
private static class MongoCalcRule
extends MongoConverterRule {
private MongoCalcRule(MongoConvention out) {
super(
- CalcRel.class,
+ LogicalCalc.class,
Convention.NONE,
out,
"MongoCalcRule");
}
public RelNode convert(RelNode rel) {
- final CalcRel calc = (CalcRel) rel;
+ final LogicalCalc calc = (LogicalCalc) rel;
// If there's a multiset, let FarragoMultisetSplitter work on it
// first.
@@ -283,7 +297,7 @@ public class MongoRules {
calc.getChild(),
calc.getTraitSet().replace(out)),
calc.getProgram(),
- ProjectRelBase.Flags.Boxed);
+ Project.Flags.Boxed);
}
}
@@ -291,7 +305,7 @@ public class MongoRules {
private final RexProgram program;
/**
- * Values defined in {@link org.eigenbase.rel.ProjectRelBase.Flags}.
+ * Values defined in {@link org.apache.calcite.rel.core.Project.Flags}.
o/
protected int flags;
@@ -313,7 +327,7 @@ public class MongoRules {
}
public double getRows() {
- return FilterRel.estimateFilteredRows(
+ return LogicalFilter.estimateFilteredRows(
getChild(), program);
}
@@ -421,26 +435,26 @@ public class MongoRules {
*/
/**
- * Rule to convert an {@link org.eigenbase.rel.AggregateRel} to an
- * {@link MongoAggregateRel}.
+ * Rule to convert an {@link org.apache.calcite.rel.logical.LogicalAggregate}
+ * to an {@link MongoAggregate}.
*/
private static class MongoAggregateRule extends MongoConverterRule {
public static final RelOptRule INSTANCE = new MongoAggregateRule();
private MongoAggregateRule() {
- super(AggregateRel.class, Convention.NONE, MongoRel.CONVENTION,
+ super(LogicalAggregate.class, Convention.NONE, MongoRel.CONVENTION,
"MongoAggregateRule");
}
public RelNode convert(RelNode rel) {
- final AggregateRel agg = (AggregateRel) rel;
+ final LogicalAggregate agg = (LogicalAggregate) rel;
final RelTraitSet traitSet =
agg.getTraitSet().replace(out);
try {
- return new MongoAggregateRel(
+ return new MongoAggregate(
rel.getCluster(),
traitSet,
- convert(agg.getChild(), traitSet),
+ convert(agg.getInput(), traitSet),
agg.getGroupSet(),
agg.getAggCallList());
} catch (InvalidRelException e) {
@@ -452,21 +466,21 @@ public class MongoRules {
/*
/**
- * Rule to convert an {@link org.eigenbase.rel.UnionRel} to a
+ * Rule to convert an {@link org.apache.calcite.rel.logical.Union} to a
* {@link MongoUnionRel}.
o/
private static class MongoUnionRule
extends MongoConverterRule {
private MongoUnionRule(MongoConvention out) {
super(
- UnionRel.class,
+ Union.class,
Convention.NONE,
out,
"MongoUnionRule");
}
public RelNode convert(RelNode rel) {
- final UnionRel union = (UnionRel) rel;
+ final Union union = (Union) rel;
final RelTraitSet traitSet =
union.getTraitSet().replace(out);
return new MongoUnionRel(
@@ -478,7 +492,7 @@ public class MongoRules {
}
public static class MongoUnionRel
- extends UnionRelBase
+ extends Union
implements MongoRel {
public MongoUnionRel(
RelOptCluster cluster,
@@ -493,8 +507,7 @@ public class MongoRules {
return new MongoUnionRel(getCluster(), traitSet, inputs, all);
}
- @Override
- public RelOptCost computeSelfCost(RelOptPlanner planner) {
+ @Override public RelOptCost computeSelfCost(RelOptPlanner planner) {
return super.computeSelfCost(planner).multiplyBy(.1);
}
@@ -504,7 +517,7 @@ public class MongoRules {
}
private static SqlString setOpSql(
- SetOpRel setOpRel, MongoImplementor implementor, String op) {
+ SetOp setOpRel, MongoImplementor implementor, String op) {
final SqlBuilder buf = new SqlBuilder(implementor.dialect);
for (Ord<RelNode> input : Ord.zip(setOpRel.getInputs())) {
if (input.i > 0) {
@@ -518,21 +531,21 @@ public class MongoRules {
}
/**
- * Rule to convert an {@link org.eigenbase.rel.IntersectRel} to an
- * {@link MongoIntersectRel}.
+ * Rule to convert an {@link org.apache.calcite.rel.logical.LogicalIntersect}
+ * to an {@link MongoIntersectRel}.
o/
private static class MongoIntersectRule
extends MongoConverterRule {
private MongoIntersectRule(MongoConvention out) {
super(
- IntersectRel.class,
+ LogicalIntersect.class,
Convention.NONE,
out,
"MongoIntersectRule");
}
public RelNode convert(RelNode rel) {
- final IntersectRel intersect = (IntersectRel) rel;
+ final LogicalIntersect intersect = (LogicalIntersect) rel;
if (intersect.all) {
return null; // INTERSECT ALL not implemented
}
@@ -547,7 +560,7 @@ public class MongoRules {
}
public static class MongoIntersectRel
- extends IntersectRelBase
+ extends Intersect
implements MongoRel {
public MongoIntersectRel(
RelOptCluster cluster,
@@ -569,21 +582,21 @@ public class MongoRules {
}
/**
- * Rule to convert an {@link org.eigenbase.rel.MinusRel} to an
- * {@link MongoMinusRel}.
+ * Rule to convert an {@link org.apache.calcite.rel.logical.LogicalMinus}
+ * to an {@link MongoMinusRel}.
o/
private static class MongoMinusRule
extends MongoConverterRule {
private MongoMinusRule(MongoConvention out) {
super(
- MinusRel.class,
+ LogicalMinus.class,
Convention.NONE,
out,
"MongoMinusRule");
}
public RelNode convert(RelNode rel) {
- final MinusRel minus = (MinusRel) rel;
+ final LogicalMinus minus = (LogicalMinus) rel;
if (minus.all) {
return null; // EXCEPT ALL not implemented
}
@@ -598,7 +611,7 @@ public class MongoRules {
}
public static class MongoMinusRel
- extends MinusRelBase
+ extends Minus
implements MongoRel {
public MongoMinusRel(
RelOptCluster cluster,
@@ -622,15 +635,14 @@ public class MongoRules {
public static class MongoValuesRule extends MongoConverterRule {
private MongoValuesRule(MongoConvention out) {
super(
- ValuesRel.class,
+ LogicalValues.class,
Convention.NONE,
out,
"MongoValuesRule");
}
- @Override
- public RelNode convert(RelNode rel) {
- ValuesRel valuesRel = (ValuesRel) rel;
+ @Override public RelNode convert(RelNode rel) {
+ LogicalValues valuesRel = (LogicalValues) rel;
return new MongoValuesRel(
valuesRel.getCluster(),
valuesRel.getRowType(),
@@ -640,7 +652,7 @@ public class MongoRules {
}
public static class MongoValuesRel
- extends ValuesRelBase
+ extends Values
implements MongoRel {
MongoValuesRel(
RelOptCluster cluster,
@@ -650,8 +662,7 @@ public class MongoRules {
super(cluster, rowType, tuples, traitSet);
}
- @Override
- public RelNode copy(
+ @Override public RelNode copy(
RelTraitSet traitSet, List<RelNode> inputs) {
assert inputs.isEmpty();
return new MongoValuesRel(
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java
index 34905ff..5bfc3f6 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchema.java
@@ -14,17 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
+package org.apache.calcite.adapter.mongodb;
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.impl.AbstractSchema;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.impl.AbstractSchema;
import com.google.common.collect.ImmutableMap;
-
import com.mongodb.DB;
import com.mongodb.MongoClient;
-import java.util.*;
+import java.util.Map;
/**
* Schema mapped onto a directory of MONGO files. Each table in the schema
@@ -49,8 +48,7 @@ public class MongoSchema extends AbstractSchema {
}
}
- @Override
- protected Map<String, Table> getTableMap() {
+ @Override protected Map<String, Table> getTableMap() {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
for (String collectionName : mongoDb.getCollectionNames()) {
builder.put(collectionName, new MongoTable(collectionName));
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java
index 10c57fd..46ceddb 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoSchemaFactory.java
@@ -14,9 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.mongodb;
+package org.apache.calcite.adapter.mongodb;
-import net.hydromatic.optiq.*;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.schema.SchemaFactory;
+import org.apache.calcite.schema.SchemaPlus;
import java.util.Map;