You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by mm...@apache.org on 2018/07/20 17:41:16 UTC
[03/53] [abbrv] calcite git commit: [CALCITE-2259] Allow Java 8 syntax
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java
index 3437a42..129ecaf 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java
@@ -16,9 +16,6 @@
*/
package org.apache.calcite.linq4j.tree;
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
@@ -28,6 +25,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.stream.Collectors;
/**
* Represents an expression that has a constant value.
@@ -154,14 +152,14 @@ public class ConstantExpression extends Expression {
}
return writer.append(")");
} catch (ArithmeticException e) {
- return writer.append("new java.math.BigDecimal(\"").append(
- bigDecimal.toString()).append("\")");
+ return writer.append("new java.math.BigDecimal(\"")
+ .append(bigDecimal.toString()).append("\")");
}
}
if (value instanceof BigInteger) {
BigInteger bigInteger = (BigInteger) value;
- return writer.append("new java.math.BigInteger(\"").append(
- bigInteger.toString()).append("\")");
+ return writer.append("new java.math.BigInteger(\"")
+ .append(bigInteger.toString()).append("\")");
}
if (value instanceof Class) {
Class clazz = (Class) value;
@@ -191,16 +189,15 @@ public class ConstantExpression extends Expression {
if (constructor != null) {
writer.append("new ").append(value.getClass());
list(writer,
- Lists.transform(Arrays.asList(value.getClass().getFields()),
- new Function<Field, Object>() {
- public Object apply(Field field) {
- try {
- return field.get(value);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- }
+ Arrays.stream(value.getClass().getFields())
+ .map(field -> {
+ try {
+ return field.get(value);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
}
- }),
+ })
+ .collect(Collectors.toList()),
"(\n", ",\n", ")");
return writer;
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java
index 1aa28b4..a4775be 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java
@@ -16,7 +16,6 @@
*/
package org.apache.calcite.linq4j.tree;
-import com.google.common.base.Function;
import com.google.common.collect.Lists;
import java.lang.reflect.Modifier;
@@ -68,16 +67,13 @@ public class ConstructorDeclaration extends MemberDeclaration {
writer
.append(resultType)
.list("(", ", ", ")",
- Lists.transform(parameters,
- new Function<ParameterExpression, String>() {
- public String apply(ParameterExpression parameter) {
- final String modifiers =
- Modifier.toString(parameter.modifier);
- return modifiers + (modifiers.isEmpty() ? "" : " ")
- + Types.className(parameter.getType()) + " "
- + parameter.name;
- }
- }))
+ Lists.transform(parameters, parameter -> {
+ final String modifiers1 =
+ Modifier.toString(parameter.modifier);
+ return modifiers1 + (modifiers1.isEmpty() ? "" : " ")
+ + Types.className(parameter.getType()) + " "
+ + parameter.name;
+ }))
.append(' ').append(body);
writer.newlineAndIndent();
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java
index 6407383..38f2057 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java
@@ -69,7 +69,7 @@ public class DeterministicCodeOptimizer extends ClassDeclarationFinder {
Pattern.compile(Pattern.quote(FIELD_PREFIX));
private static final Set<Class> DETERMINISTIC_CLASSES =
- ImmutableSet.<Class>of(Byte.class, Boolean.class, Short.class,
+ ImmutableSet.of(Byte.class, Boolean.class, Short.class,
Integer.class, Long.class, BigInteger.class, BigDecimal.class,
String.class, Math.class);
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java
index 5d7f83d..bf6ef79 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java
@@ -24,6 +24,8 @@ import org.apache.calcite.linq4j.function.Function2;
import org.apache.calcite.linq4j.function.Predicate1;
import org.apache.calcite.linq4j.function.Predicate2;
+import com.google.common.collect.ImmutableList;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
@@ -524,7 +526,7 @@ public abstract class Expressions {
*/
public static ConditionalExpression condition(Expression test,
Expression ifTrue, Expression ifFalse, Type type) {
- return new ConditionalExpression(Arrays.<Node>asList(test, ifFalse, ifTrue),
+ return new ConditionalExpression(Arrays.asList(test, ifFalse, ifTrue),
type);
}
@@ -962,7 +964,7 @@ public abstract class Expressions {
* block with an if statement.
*/
public static ConditionalStatement ifThen(Expression test, Node ifTrue) {
- return new ConditionalStatement(Arrays.<Node>asList(test, ifTrue));
+ return new ConditionalStatement(Arrays.asList(test, ifTrue));
}
/**
@@ -971,7 +973,7 @@ public abstract class Expressions {
*/
public static ConditionalStatement ifThenElse(Expression test, Node ifTrue,
Node ifFalse) {
- return new ConditionalStatement(Arrays.<Node>asList(test, ifTrue, ifFalse));
+ return new ConditionalStatement(Arrays.asList(test, ifTrue, ifFalse));
}
/**
@@ -1914,8 +1916,7 @@ public abstract class Expressions {
* constructor that takes no arguments.
*/
public static NewExpression new_(Constructor constructor) {
- return new_(
- constructor.getDeclaringClass(), Collections.<Expression>emptyList());
+ return new_(constructor.getDeclaringClass(), ImmutableList.of());
}
/**
@@ -1923,7 +1924,7 @@ public abstract class Expressions {
* parameterless constructor of the specified type.
*/
public static NewExpression new_(Type type) {
- return new_(type, Collections.<Expression>emptyList());
+ return new_(type, ImmutableList.of());
}
/**
@@ -2837,8 +2838,7 @@ public abstract class Expressions {
* finally block and no catch statements.
*/
public static TryStatement tryFinally(Statement body, Statement finally_) {
- return new TryStatement(body, Collections.<CatchBlock>emptyList(),
- finally_);
+ return new TryStatement(body, ImmutableList.of(), finally_);
}
/**
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java
index 3bbe26a..a5f04cb 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java
@@ -19,13 +19,14 @@ package org.apache.calcite.linq4j.tree;
import org.apache.calcite.linq4j.function.Function;
import org.apache.calcite.linq4j.function.Functions;
-import java.lang.reflect.InvocationHandler;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -59,8 +60,7 @@ public final class FunctionExpression<F extends Function<?>>
}
public FunctionExpression(F function) {
- this((Class) function.getClass(), function, null,
- Collections.<ParameterExpression>emptyList());
+ this((Class) function.getClass(), function, null, ImmutableList.of());
}
public FunctionExpression(Class<F> type, BlockStatement body,
@@ -79,14 +79,12 @@ public final class FunctionExpression<F extends Function<?>>
}
public Invokable compile() {
- return new Invokable() {
- public Object dynamicInvoke(Object... args) {
- final Evaluator evaluator = new Evaluator();
- for (int i = 0; i < args.length; i++) {
- evaluator.push(parameterList.get(i), args[i]);
- }
- return evaluator.evaluate(body);
+ return args -> {
+ final Evaluator evaluator = new Evaluator();
+ for (int i = 0; i < args.length; i++) {
+ evaluator.push(parameterList.get(i), args[i]);
}
+ return evaluator.evaluate(body);
};
}
@@ -99,13 +97,7 @@ public final class FunctionExpression<F extends Function<?>>
//noinspection unchecked
dynamicFunction = (F) Proxy.newProxyInstance(getClass().getClassLoader(),
- new Class[]{Types.toClass(type)},
- new InvocationHandler() {
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- return x.dynamicInvoke(args);
- }
- });
+ new Class[]{Types.toClass(type)}, (proxy, method, args) -> x.dynamicInvoke(args));
}
return dynamicFunction;
}
@@ -223,9 +215,13 @@ public final class FunctionExpression<F extends Function<?>>
private Method getAbstractMethod() {
if (type instanceof Class
- && ((Class) type).isInterface()
- && ((Class) type).getDeclaredMethods().length == 1) {
- return ((Class) type).getDeclaredMethods()[0];
+ && ((Class) type).isInterface()) {
+ final List<Method> declaredMethods =
+ Lists.newArrayList(((Class) type).getDeclaredMethods());
+ declaredMethods.removeIf(m -> (m.getModifiers() & 0x00001000) != 0);
+ if (declaredMethods.size() == 1) {
+ return declaredMethods.get(0);
+ }
}
return null;
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java
index 800f387..6449594 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java
@@ -16,7 +16,6 @@
*/
package org.apache.calcite.linq4j.tree;
-import com.google.common.base.Function;
import com.google.common.collect.Lists;
import java.lang.reflect.Modifier;
@@ -69,12 +68,7 @@ public class MethodDeclaration extends MemberDeclaration {
.append(' ')
.append(name)
.list("(", ", ", ")",
- Lists.transform(parameters,
- new Function<ParameterExpression, String>() {
- public String apply(ParameterExpression a0) {
- return a0.declString();
- }
- }))
+ Lists.transform(parameters, ParameterExpression::declString))
.append(' ')
.append(body);
writer.newlineAndIndent();
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java
index 9313011..6b6c072 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java
@@ -16,8 +16,6 @@
*/
package org.apache.calcite.linq4j.tree;
-import com.google.common.base.Preconditions;
-
import java.util.List;
import java.util.Objects;
@@ -32,8 +30,8 @@ public class TryStatement extends Statement {
public TryStatement(Statement body, List<CatchBlock> catchBlocks,
Statement fynally) {
super(ExpressionType.Try, body.getType());
- this.body = Preconditions.checkNotNull(body);
- this.catchBlocks = Preconditions.checkNotNull(catchBlocks);
+ this.body = Objects.requireNonNull(body);
+ this.catchBlocks = Objects.requireNonNull(catchBlocks);
this.fynally = fynally;
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java
index b4f233a..442b927 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java
@@ -153,7 +153,7 @@ public abstract class Types {
for (Type type : types) {
classes.add(toClass(type));
}
- return classes.toArray(new Class[classes.size()]);
+ return classes.toArray(new Class[0]);
}
static Class[] toClassArray(Iterable<? extends Expression> arguments) {
@@ -161,7 +161,7 @@ public abstract class Types {
for (Expression argument : arguments) {
classes.add(toClass(argument.getType()));
}
- return classes.toArray(new Class[classes.size()]);
+ return classes.toArray(new Class[0]);
}
/**
@@ -562,7 +562,7 @@ public abstract class Types {
}
public Type[] getActualTypeArguments() {
- return typeArguments.toArray(new Type[typeArguments.size()]);
+ return typeArguments.toArray(new Type[0]);
}
public Type getRawType() {
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/test/java/com/example/Linq4jExample.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/com/example/Linq4jExample.java b/linq4j/src/test/java/com/example/Linq4jExample.java
index 80413bf..994b836 100644
--- a/linq4j/src/test/java/com/example/Linq4jExample.java
+++ b/linq4j/src/test/java/com/example/Linq4jExample.java
@@ -19,7 +19,6 @@ package com.example;
import org.apache.calcite.linq4j.Linq4j;
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;
/**
@@ -53,32 +52,16 @@ public class Linq4jExample {
};
public static final Function1<Employee, Integer> EMP_DEPTNO_SELECTOR =
- new Function1<Employee, Integer>() {
- public Integer apply(Employee employee) {
- return employee.deptno;
- }
- };
+ employee -> employee.deptno;
public static void main(String[] args) {
String s = Linq4j.asEnumerable(EMPS)
.groupBy(
EMP_DEPTNO_SELECTOR,
- new Function0<String>() {
- public String apply() {
- return null;
- }
- },
- new Function2<String, Employee, String>() {
- public String apply(String v1, Employee e0) {
- return v1 == null ? e0.name : (v1 + "+" + e0.name);
- }
- },
- new Function2<Integer, String, String>() {
- public String apply(Integer v1, String v2) {
- return v1 + ": " + v2;
- }
- })
- .orderBy(Functions.<String>identitySelector())
+ (Function0<String>) () -> null,
+ (v1, e0) -> v1 == null ? e0.name : (v1 + "+" + e0.name),
+ (v1, v2) -> v1 + ": " + v2)
+ .orderBy(Functions.identitySelector())
.toList()
.toString();
assert s.equals("[10: Fred+Eric+Janet, 30: Bill]");
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/test/java/org/apache/calcite/linq4j/function/FunctionTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/function/FunctionTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/function/FunctionTest.java
index 998aed3..9eac08c 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/function/FunctionTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/function/FunctionTest.java
@@ -32,32 +32,17 @@ public class FunctionTest {
final List<String> abc = Arrays.asList("A", "B", "C", "D");
// a miss, then a hit
Assert.assertEquals("[A, C, D]",
- Functions.filter(abc,
- new Predicate1<String>() {
- public boolean apply(String v1) {
- return !v1.equals("B");
- }
- }).toString());
+ Functions.filter(abc, v1 -> !v1.equals("B")).toString());
// a hit, then all misses
Assert.assertEquals("[A]",
- Functions.filter(abc,
- new Predicate1<String>() {
- public boolean apply(String v1) {
- return v1.equals("A");
- }
- }).toString());
+ Functions.filter(abc, v1 -> v1.equals("A")).toString());
// two hits, then a miss
Assert.assertEquals("[A, B, D]",
- Functions.filter(abc,
- new Predicate1<String>() {
- public boolean apply(String v1) {
- return !v1.equals("C");
- }
- }).toString());
+ Functions.filter(abc, v1 -> !v1.equals("C")).toString());
Assert.assertSame(Collections.emptyList(),
- Functions.filter(abc, Functions.<String>falsePredicate1()));
+ Functions.filter(abc, Functions.falsePredicate1()));
Assert.assertSame(abc,
- Functions.filter(abc, Functions.<String>truePredicate1()));
+ Functions.filter(abc, Functions.truePredicate1()));
}
/** Unit test for {@link Functions#exists}. */
@@ -65,16 +50,11 @@ public class FunctionTest {
final List<Integer> ints = Arrays.asList(1, 10, 2);
final List<Integer> empty = Collections.emptyList();
Assert.assertFalse(
- Functions.exists(ints,
- new Predicate1<Integer>() {
- public boolean apply(Integer v1) {
- return v1 > 20;
- }
- }));
+ Functions.exists(ints, v1 -> v1 > 20));
Assert.assertFalse(
- Functions.exists(empty, Functions.<Integer>falsePredicate1()));
+ Functions.exists(empty, Functions.falsePredicate1()));
Assert.assertFalse(
- Functions.exists(empty, Functions.<Integer>truePredicate1()));
+ Functions.exists(empty, Functions.truePredicate1()));
}
/** Unit test for {@link Functions#all}. */
@@ -82,30 +62,15 @@ public class FunctionTest {
final List<Integer> ints = Arrays.asList(1, 10, 2);
final List<Integer> empty = Collections.emptyList();
Assert.assertFalse(
- Functions.all(ints,
- new Predicate1<Integer>() {
- public boolean apply(Integer v1) {
- return v1 > 20;
- }
- }));
+ Functions.all(ints, v1 -> v1 > 20));
Assert.assertTrue(
- Functions.all(ints,
- new Predicate1<Integer>() {
- public boolean apply(Integer v1) {
- return v1 < 20;
- }
- }));
+ Functions.all(ints, v1 -> v1 < 20));
Assert.assertFalse(
- Functions.all(ints,
- new Predicate1<Integer>() {
- public boolean apply(Integer v1) {
- return v1 < 10;
- }
- }));
+ Functions.all(ints, v1 -> v1 < 10));
Assert.assertTrue(
- Functions.all(empty, Functions.<Integer>falsePredicate1()));
+ Functions.all(empty, Functions.falsePredicate1()));
Assert.assertTrue(
- Functions.all(empty, Functions.<Integer>truePredicate1()));
+ Functions.all(empty, Functions.truePredicate1()));
}
/** Unit test for {@link Functions#generate}. */
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/test/java/org/apache/calcite/linq4j/test/CorrelateJoinTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/CorrelateJoinTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/CorrelateJoinTest.java
index 10e4663..ab69c3c 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/CorrelateJoinTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/CorrelateJoinTest.java
@@ -20,14 +20,13 @@ import org.apache.calcite.linq4j.CorrelateJoinType;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.calcite.linq4j.Linq4j;
-import org.apache.calcite.linq4j.function.Function1;
import org.apache.calcite.linq4j.function.Function2;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
import org.junit.Test;
+import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertArrayEquals;
@@ -37,11 +36,7 @@ import static org.junit.Assert.assertArrayEquals;
*/
public class CorrelateJoinTest {
static final Function2<Integer, Integer, Integer[]> SELECT_BOTH =
- new Function2<Integer, Integer, Integer[]>() {
- public Integer[] apply(Integer v0, Integer v1) {
- return new Integer[]{v0, v1};
- }
- };
+ (v0, v1) -> new Integer[]{v0, v1};
@Test public void testInner() {
testJoin(CorrelateJoinType.INNER, new Integer[][]{
@@ -82,23 +77,20 @@ public class CorrelateJoinTest {
public void testJoin(CorrelateJoinType joinType, Integer[][] expected) {
Enumerable<Integer[]> join =
Linq4j.asEnumerable(ImmutableList.of(1, 2, 3, 10, 20, 30))
- .correlateJoin(joinType,
- new Function1<Integer, Enumerable<Integer>>() {
- public Enumerable<Integer> apply(Integer a0) {
- if (a0 == 1 || a0 == 10) {
- return Linq4j.emptyEnumerable();
- }
- if (a0 == 2 || a0 == 20) {
- return Linq4j.singletonEnumerable(a0 * 10);
- }
- if (a0 == 3 || a0 == 30) {
- return Linq4j.asEnumerable(
- ImmutableList.of(-a0 * 10, -a0 * 20));
- }
- throw new IllegalArgumentException(
- "Unexpected input " + a0);
- }
- }, SELECT_BOTH);
+ .correlateJoin(joinType, a0 -> {
+ if (a0 == 1 || a0 == 10) {
+ return Linq4j.emptyEnumerable();
+ }
+ if (a0 == 2 || a0 == 20) {
+ return Linq4j.singletonEnumerable(a0 * 10);
+ }
+ if (a0 == 3 || a0 == 30) {
+ return Linq4j.asEnumerable(
+ ImmutableList.of(-a0 * 10, -a0 * 20));
+ }
+ throw new IllegalArgumentException(
+ "Unexpected input " + a0);
+ }, SELECT_BOTH);
for (int i = 0; i < 2; i++) {
Enumerator<Integer[]> e = join.enumerator();
checkResults(e, expected);
@@ -107,7 +99,7 @@ public class CorrelateJoinTest {
}
private void checkResults(Enumerator<Integer[]> e, Integer[][] expected) {
- List<Integer[]> res = Lists.newArrayList();
+ List<Integer[]> res = new ArrayList<>();
while (e.moveNext()) {
res.add(e.current());
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/linq4j/src/test/java/org/apache/calcite/linq4j/test/DeterministicTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/DeterministicTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/DeterministicTest.java
index 9194613..7d73e85 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/DeterministicTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/DeterministicTest.java
@@ -23,7 +23,6 @@ import org.apache.calcite.linq4j.tree.ClassDeclarationFinder;
import org.apache.calcite.linq4j.tree.DeterministicCodeOptimizer;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
-import org.apache.calcite.linq4j.tree.ParameterExpression;
import org.apache.calcite.linq4j.tree.Types;
import org.junit.Test;
@@ -134,12 +133,12 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(Expressions.add(ONE, TWO))))),
equalTo("{\n"
+ " return new Runnable(){\n"
@@ -157,11 +156,11 @@ public class DeterministicTest {
optimize(
optimizeExpression(
Expressions.new_(Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(Expressions.add(ONE, TWO)))))),
equalTo("{\n"
+ " return new Runnable(){\n"
@@ -179,12 +178,12 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.multiply(Expressions.add(ONE, TWO),
Expressions.subtract(ONE, TWO)))))),
@@ -206,12 +205,12 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.multiply(Expressions.add(ONE, TWO),
THREE))))),
@@ -232,31 +231,31 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.add(
Expressions.add(ONE, FOUR),
Expressions.call(
Expressions.new_(
Callable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
Object.class,
"call",
Collections
- .<ParameterExpression>emptyList(),
+ .emptyList(),
Blocks.toFunctionBlock(
Expressions.multiply(
Expressions.add(ONE, TWO),
THREE)))),
"call",
- Collections.<Expression>emptyList())))))),
+ Collections.emptyList())))))),
equalTo("{\n"
+ " return new Runnable(){\n"
+ " int test() {\n"
@@ -280,10 +279,10 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0, int.class, "test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.new_(BigInteger.class,
Expressions.constant("42")))))),
@@ -306,10 +305,10 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0, int.class, "test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.typeIs(ONE, Boolean.class))))),
equalTo("{\n"
@@ -327,9 +326,9 @@ public class DeterministicTest {
assertThat(
optimize(
Expressions.new_(Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(0, int.class, "test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.orElse(
Expressions.typeIs(ONE, Boolean.class),
@@ -352,9 +351,9 @@ public class DeterministicTest {
assertThat(
optimize(
Expressions.new_(Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(0, int.class, "test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.call(
getMethod(Integer.class, "valueOf", int.class),
@@ -375,9 +374,9 @@ public class DeterministicTest {
assertThat(
optimize(
Expressions.new_(Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(0, int.class, "test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.call(
Expressions.field(null, BigInteger.class, "ONE"),
@@ -407,9 +406,9 @@ public class DeterministicTest {
assertThat(
optimize(
Expressions.new_(Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(0, int.class, "test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.call(
Expressions.call(null,
@@ -442,12 +441,12 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.call(null,
Types.lookupMethod(TestClass.class,
@@ -469,12 +468,12 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.call(null,
Types.lookupMethod(TestClass.class,
@@ -495,12 +494,12 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.call(null,
Types.lookupMethod(TestDeterministicClass.class,
@@ -522,12 +521,12 @@ public class DeterministicTest {
optimize(
Expressions.new_(
Runnable.class,
- Collections.<Expression>emptyList(),
+ Collections.emptyList(),
Expressions.methodDecl(
0,
int.class,
"test",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.call(null,
Types.lookupMethod(TestDeterministicClass.class,
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/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 8f1756d..f457906 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
@@ -26,7 +26,6 @@ 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;
@@ -34,6 +33,7 @@ import org.apache.calcite.linq4j.tree.ParameterExpression;
import org.apache.calcite.linq4j.tree.Shuttle;
import org.apache.calcite.linq4j.tree.Types;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
@@ -195,7 +195,7 @@ public class ExpressionTest {
Expressions.foldOr(list1)));
final List<Expression> list2 =
- Collections.<Expression>singletonList(
+ Collections.singletonList(
Expressions.constant(true));
assertEquals(
"true",
@@ -355,7 +355,7 @@ public class ExpressionTest {
Expressions.lambda(
Function1.class,
Expressions.call(
- paramX, "length", Collections.<Expression>emptyList()),
+ paramX, "length", Collections.emptyList()),
Arrays.asList(paramX))));
// 1-dimensional array with initializer
@@ -421,7 +421,7 @@ public class ExpressionTest {
Object.class),
String.class),
"length",
- Collections.<Expression>emptyList()),
+ Collections.emptyList()),
Integer.TYPE)));
// resolving a static method
@@ -635,8 +635,8 @@ public class ExpressionTest {
Expressions.statement(
Expressions.new_(
Types.of(AbstractList.class, String.class),
- Collections.<Expression>emptyList(),
- Arrays.<MemberDeclaration>asList(
+ Collections.emptyList(),
+ Arrays.asList(
Expressions.fieldDecl(
Modifier.PUBLIC | Modifier.FINAL,
Expressions.parameter(
@@ -647,12 +647,12 @@ public class ExpressionTest {
Modifier.PUBLIC,
Integer.TYPE,
"size",
- Collections.<ParameterExpression>emptyList(),
+ Collections.emptyList(),
Blocks.toFunctionBlock(
Expressions.call(
bazParameter,
"size",
- Collections.<Expression>emptyList()))),
+ Collections.emptyList()))),
Expressions.methodDecl(
Modifier.PUBLIC,
String.class,
@@ -668,8 +668,7 @@ public class ExpressionTest {
indexParameter)),
String.class),
"toUpperCase",
- Collections
- .<Expression>emptyList())))))));
+ ImmutableList.of())))))));
assertEquals(
"{\n"
+ " final java.util.List<String> baz = java.util.Arrays.asList(\"foo\", \"bar\");\n"
@@ -1049,8 +1048,8 @@ public class ExpressionTest {
final NewExpression newExpression =
Expressions.new_(
Object.class,
- Collections.<Expression>emptyList(),
- Arrays.<MemberDeclaration>asList(
+ ImmutableList.of(),
+ Arrays.asList(
Expressions.fieldDecl(
Modifier.PUBLIC | Modifier.FINAL,
Expressions.parameter(String.class, "foo"),
@@ -1059,8 +1058,8 @@ public class ExpressionTest {
Modifier.PUBLIC | Modifier.STATIC,
"MyClass",
null,
- Collections.<Type>emptyList(),
- Arrays.<MemberDeclaration>asList(
+ ImmutableList.of(),
+ Arrays.asList(
new FieldDeclaration(
0,
Expressions.parameter(int.class, "x"),