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:19 UTC
[06/53] [abbrv] calcite git commit: [CALCITE-2259] Allow Java 8 syntax
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index d710661..d1f0ee6 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -43,7 +43,6 @@ import org.apache.calcite.sql.validate.SqlValidatorUtil;
import org.apache.calcite.util.Bug;
import org.apache.calcite.util.ImmutableBitSet;
-import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
@@ -61,6 +60,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
+import java.util.function.Consumer;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
@@ -5988,16 +5988,10 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
* lurking in the validation process.
*/
@Test public void testLarge() {
- checkLarge(700,
- new Function<String, Void>() {
- public Void apply(String input) {
- check(input);
- return null;
- }
- });
+ checkLarge(700, this::check);
}
- static void checkLarge(int x, Function<String, Void> f) {
+ static void checkLarge(int x, Consumer<String> f) {
if (System.getProperty("os.name").startsWith("Windows")) {
// NOTE jvs 1-Nov-2006: Default thread stack size
// on Windows is too small, so avoid stack overflow
@@ -6006,24 +6000,24 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
// E.g. large = "deptno * 1 + deptno * 2 + deptno * 3".
String large = list(" + ", "deptno * ", x);
- f.apply("select " + large + "from emp");
- f.apply("select distinct " + large + "from emp");
- f.apply("select " + large + " from emp " + "group by deptno");
- f.apply("select * from emp where " + large + " > 5");
- f.apply("select * from emp order by " + large + " desc");
- f.apply("select " + large + " from emp order by 1");
- f.apply("select distinct " + large + " from emp order by " + large);
+ f.accept("select " + large + "from emp");
+ f.accept("select distinct " + large + "from emp");
+ f.accept("select " + large + " from emp " + "group by deptno");
+ f.accept("select * from emp where " + large + " > 5");
+ f.accept("select * from emp order by " + large + " desc");
+ f.accept("select " + large + " from emp order by 1");
+ f.accept("select distinct " + large + " from emp order by " + large);
// E.g. "in (0, 1, 2, ...)"
- f.apply("select * from emp where deptno in (" + list(", ", "", x) + ")");
+ f.accept("select * from emp where deptno in (" + list(", ", "", x) + ")");
// E.g. "where x = 1 or x = 2 or x = 3 ..."
- f.apply("select * from emp where " + list(" or ", "deptno = ", x));
+ f.accept("select * from emp where " + list(" or ", "deptno = ", x));
// E.g. "select x1, x2 ... from (
// select 'a' as x1, 'a' as x2, ... from emp union
// select 'bb' as x1, 'bb' as x2, ... from dept)"
- f.apply("select " + list(", ", "x", x)
+ f.accept("select " + list(", ", "x", x)
+ " from (select " + list(", ", "'a' as x", x) + " from emp "
+ "union all select " + list(", ", "'bb' as x", x) + " from dept)");
}
@@ -8544,20 +8538,17 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
* the documentation</a>. */
@Test public void testOperatorsSortedByPrecedence() {
final StringBuilder b = new StringBuilder();
- final Comparator<SqlOperator> comparator =
- new Comparator<SqlOperator>() {
- public int compare(SqlOperator o1, SqlOperator o2) {
- int c = Integer.compare(prec(o1), prec(o2));
- if (c != 0) {
- return -c;
- }
- c = o1.getName().compareTo(o2.getName());
- if (c != 0) {
- return c;
- }
- return o1.getSyntax().compareTo(o2.getSyntax());
- }
- };
+ final Comparator<SqlOperator> comparator = (o1, o2) -> {
+ int c = Integer.compare(prec(o1), prec(o2));
+ if (c != 0) {
+ return -c;
+ }
+ c = o1.getName().compareTo(o2.getName());
+ if (c != 0) {
+ return c;
+ }
+ return o1.getSyntax().compareTo(o2.getSyntax());
+ };
final List<SqlOperator> operators =
SqlStdOperatorTable.instance().getOperatorList();
int p = -1;
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java
index b78df79..7e983dd 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java
@@ -28,7 +28,6 @@ import org.apache.calcite.sql.test.DelegatingSqlTestFactory;
import org.apache.calcite.sql.test.SqlTestFactory;
import org.apache.calcite.sql.test.SqlTester;
import org.apache.calcite.sql.test.SqlTesterImpl;
-import org.apache.calcite.sql.test.SqlTests;
import org.apache.calcite.sql.validate.SqlConformance;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.calcite.sql.validate.SqlMonotonicity;
@@ -620,13 +619,9 @@ public class SqlValidatorTestCase {
}
public Sql bindType(final String bindType) {
- tester.check(sql, null,
- new SqlTester.ParameterChecker() {
- public void checkParameters(RelDataType parameterRowType) {
- assertThat(parameterRowType.toString(), is(bindType));
- }
- },
- SqlTests.ANY_RESULT_CHECKER);
+ tester.check(sql, null, parameterRowType ->
+ assertThat(parameterRowType.toString(), is(bindType)),
+ result -> { });
return this;
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/StreamTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/StreamTest.java b/core/src/test/java/org/apache/calcite/test/StreamTest.java
index d425f30..b25da6d 100644
--- a/core/src/test/java/org/apache/calcite/test/StreamTest.java
+++ b/core/src/test/java/org/apache/calcite/test/StreamTest.java
@@ -37,9 +37,7 @@ import org.apache.calcite.schema.TableFactory;
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.util.ImmutableBitSet;
-import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -51,6 +49,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Map;
+import java.util.function.Consumer;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
@@ -246,36 +245,29 @@ public class StreamTest {
.withDefaultSchema(INFINITE_STREAM_SCHEMA_NAME)
.query("select stream * from orders")
.explainContains(explain)
- .returns(
- new Function<ResultSet, Void>() {
- public Void apply(final ResultSet resultSet) {
- int n = 0;
- try {
- while (resultSet.next()) {
- if (++n == 5) {
- new Thread(
- new Runnable() {
- @Override public void run() {
- try {
- Thread.sleep(3);
- resultSet.getStatement().cancel();
- } catch (InterruptedException | SQLException e) {
- // ignore
- }
- }
- }).start();
- }
+ .returns(resultSet -> {
+ int n = 0;
+ try {
+ while (resultSet.next()) {
+ if (++n == 5) {
+ new Thread(() -> {
+ try {
+ Thread.sleep(3);
+ resultSet.getStatement().cancel();
+ } catch (InterruptedException | SQLException e) {
+ // ignore
}
- fail("expected cancel, got end-of-data");
- } catch (SQLException e) {
- assertThat(e.getMessage(), is("Statement canceled"));
- }
- // With a 3 millisecond delay, typically n is between 200 - 400
- // before cancel takes effect.
- assertTrue("n is " + n, n > 5);
- return null;
+ }).start();
}
- });
+ }
+ fail("expected cancel, got end-of-data");
+ } catch (SQLException e) {
+ assertThat(e.getMessage(), is("Statement canceled"));
+ }
+ // With a 3 millisecond delay, typically n is between 200 - 400
+ // before cancel takes effect.
+ assertTrue("n is " + n, n > 5);
+ });
}
@Test public void testStreamToRelationJoin() {
@@ -332,26 +324,23 @@ public class StreamTest {
.query(sql);
}
- private Function<ResultSet, Void> startsWith(String... rows) {
+ private Consumer<ResultSet> startsWith(String... rows) {
final ImmutableList<String> rowList = ImmutableList.copyOf(rows);
- return new Function<ResultSet, Void>() {
- public Void apply(ResultSet input) {
- try {
- final CalciteAssert.ResultSetFormatter formatter =
- new CalciteAssert.ResultSetFormatter();
- final ResultSetMetaData metaData = input.getMetaData();
- for (String expectedRow : rowList) {
- if (!input.next()) {
- throw new AssertionError("input ended too soon");
- }
- formatter.rowToString(input, metaData);
- String actualRow = formatter.string();
- assertThat(actualRow, equalTo(expectedRow));
+ return resultSet -> {
+ try {
+ final CalciteAssert.ResultSetFormatter formatter =
+ new CalciteAssert.ResultSetFormatter();
+ final ResultSetMetaData metaData = resultSet.getMetaData();
+ for (String expectedRow : rowList) {
+ if (!resultSet.next()) {
+ throw new AssertionError("input ended too soon");
}
- return null;
- } catch (SQLException e) {
- throw new RuntimeException(e);
+ formatter.rowToString(resultSet, metaData);
+ String actualRow = formatter.string();
+ assertThat(actualRow, equalTo(expectedRow));
}
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
}
};
}
@@ -361,24 +350,19 @@ public class StreamTest {
* functions.
*/
private abstract static class BaseOrderStreamTable implements ScannableTable {
- protected final RelProtoDataType protoRowType = new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory a0) {
- return a0.builder()
- .add("ROWTIME", SqlTypeName.TIMESTAMP)
- .add("ID", SqlTypeName.INTEGER)
- .add("PRODUCT", SqlTypeName.VARCHAR, 10)
- .add("UNITS", SqlTypeName.INTEGER)
- .build();
- }
- };
+ protected final RelProtoDataType protoRowType = a0 -> a0.builder()
+ .add("ROWTIME", SqlTypeName.TIMESTAMP)
+ .add("ID", SqlTypeName.INTEGER)
+ .add("PRODUCT", SqlTypeName.VARCHAR, 10)
+ .add("UNITS", SqlTypeName.INTEGER)
+ .build();
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
return protoRowType.apply(typeFactory);
}
public Statistic getStatistic() {
- return Statistics.of(100d,
- ImmutableList.<ImmutableBitSet>of(),
+ return Statistics.of(100d, ImmutableList.of(),
RelCollations.createSingleton(0));
}
@@ -391,8 +375,7 @@ public class StreamTest {
}
@Override public boolean rolledUpColumnValidInsideAgg(String column,
- SqlCall call, SqlNode parent,
- CalciteConnectionConfig config) {
+ SqlCall call, SqlNode parent, CalciteConnectionConfig config) {
return false;
}
}
@@ -447,8 +430,7 @@ public class StreamTest {
}
@Override public boolean rolledUpColumnValidInsideAgg(String column,
- SqlCall call, SqlNode parent,
- CalciteConnectionConfig config) {
+ SqlCall call, SqlNode parent, CalciteConnectionConfig config) {
return false;
}
}
@@ -485,21 +467,17 @@ public class StreamTest {
public static class InfiniteOrdersTable extends BaseOrderStreamTable
implements StreamableTable {
public Enumerable<Object[]> scan(DataContext root) {
- return Linq4j.asEnumerable(new Iterable<Object[]>() {
- @Override public Iterator<Object[]> iterator() {
- return new Iterator<Object[]>() {
- public boolean hasNext() {
- return true;
- }
+ return Linq4j.asEnumerable(() -> new Iterator<Object[]>() {
+ public boolean hasNext() {
+ return true;
+ }
- public Object[] next() {
- return ROW_GENERATOR.apply();
- }
+ public Object[] next() {
+ return ROW_GENERATOR.apply();
+ }
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
+ public void remove() {
+ throw new UnsupportedOperationException();
}
});
}
@@ -547,14 +525,10 @@ public class StreamTest {
this.rows = rows;
}
- private final RelProtoDataType protoRowType = new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory a0) {
- return a0.builder()
- .add("ID", SqlTypeName.VARCHAR, 32)
- .add("SUPPLIER", SqlTypeName.INTEGER)
- .build();
- }
- };
+ private final RelProtoDataType protoRowType = a0 -> a0.builder()
+ .add("ID", SqlTypeName.VARCHAR, 32)
+ .add("SUPPLIER", SqlTypeName.INTEGER)
+ .build();
public Enumerable<Object[]> scan(DataContext root) {
return Linq4j.asEnumerable(rows);
@@ -565,7 +539,7 @@ public class StreamTest {
}
public Statistic getStatistic() {
- return Statistics.of(200d, ImmutableList.<ImmutableBitSet>of());
+ return Statistics.of(200d, ImmutableList.of());
}
public Schema.TableType getJdbcTableType() {
@@ -577,8 +551,7 @@ public class StreamTest {
}
@Override public boolean rolledUpColumnValidInsideAgg(String column,
- SqlCall call, SqlNode parent,
- CalciteConnectionConfig config) {
+ SqlCall call, SqlNode parent, CalciteConnectionConfig config) {
return false;
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java b/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java
index b56d2f6..55ba318 100644
--- a/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java
+++ b/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java
@@ -27,8 +27,6 @@ import org.apache.calcite.schema.impl.TableFunctionImpl;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.calcite.util.Smalls;
-import com.google.common.base.Function;
-
import org.junit.Ignore;
import org.junit.Test;
@@ -382,22 +380,18 @@ public class TableFunctionTest {
final String q = "select *\n"
+ "from table(\"s\".\"fibonacci\"())";
with().query(q)
- .returns(
- new Function<ResultSet, Void>() {
- public Void apply(ResultSet r) {
- try {
- final List<Long> numbers = new ArrayList<>();
- while (r.next() && numbers.size() < 13) {
- numbers.add(r.getLong(1));
- }
- assertThat(numbers.toString(),
- is("[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]"));
- return null;
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
- });
+ .returns(r -> {
+ try {
+ final List<Long> numbers = new ArrayList<>();
+ while (r.next() && numbers.size() < 13) {
+ numbers.add(r.getLong(1));
+ }
+ assertThat(numbers.toString(),
+ is("[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]"));
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ });
}
@Test public void testUserDefinedTableFunction7() {
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/UdfTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/UdfTest.java b/core/src/test/java/org/apache/calcite/test/UdfTest.java
index 6dc822a..10c7458 100644
--- a/core/src/test/java/org/apache/calcite/test/UdfTest.java
+++ b/core/src/test/java/org/apache/calcite/test/UdfTest.java
@@ -17,19 +17,15 @@
package org.apache.calcite.test;
import org.apache.calcite.adapter.enumerable.CallImplementor;
-import org.apache.calcite.adapter.enumerable.RexImpTable.NullAs;
-import org.apache.calcite.adapter.enumerable.RexToLixTranslator;
import org.apache.calcite.adapter.java.ReflectiveSchema;
import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.linq4j.Ord;
import org.apache.calcite.linq4j.function.SemiStrict;
-import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.apache.calcite.linq4j.tree.Types;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelProtoDataType;
-import org.apache.calcite.rex.RexCall;
import org.apache.calcite.schema.FunctionParameter;
import org.apache.calcite.schema.ImplementableFunction;
import org.apache.calcite.schema.ScalarFunction;
@@ -244,7 +240,7 @@ public class UdfTest {
+ " POST.MY_INCREMENT(\"empid\", 10) as INCREMENTED_SALARY\n"
+ "from \"hr\".\"emps\"";
post.add("V_EMP",
- ViewTable.viewMacro(post, viewSql, ImmutableList.<String>of(),
+ ViewTable.viewMacro(post, viewSql, ImmutableList.of(),
ImmutableList.of("POST", "V_EMP"), null));
final String result = ""
@@ -998,14 +994,12 @@ public class UdfTest {
protected abstract List<RelProtoDataType> getParams();
@Override public CallImplementor getImplementor() {
- return new CallImplementor() {
- public Expression implement(RexToLixTranslator translator, RexCall call, NullAs nullAs) {
- Method lookupMethod =
- Types.lookupMethod(Smalls.AllTypesFunction.class,
- "arrayAppendFun", List.class, Integer.class);
- return Expressions.call(lookupMethod,
- translator.translateList(call.getOperands(), nullAs));
- }
+ return (translator, call, nullAs) -> {
+ Method lookupMethod =
+ Types.lookupMethod(Smalls.AllTypesFunction.class,
+ "arrayAppendFun", List.class, Integer.class);
+ return Expressions.call(lookupMethod,
+ translator.translateList(call.getOperands(), nullAs));
};
}
}
@@ -1020,17 +1014,9 @@ public class UdfTest {
@Override public List<RelProtoDataType> getParams() {
return ImmutableList.of(
- new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory typeFactory) {
- return typeFactory.createArrayType(
- typeFactory.createSqlType(SqlTypeName.INTEGER), -1);
- }
- },
- new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory typeFactory) {
- return typeFactory.createSqlType(SqlTypeName.INTEGER);
- }
- });
+ typeFactory -> typeFactory.createArrayType(
+ typeFactory.createSqlType(SqlTypeName.INTEGER), -1),
+ typeFactory -> typeFactory.createSqlType(SqlTypeName.INTEGER));
}
}
@@ -1044,17 +1030,9 @@ public class UdfTest {
public List<RelProtoDataType> getParams() {
return ImmutableList.of(
- new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory typeFactory) {
- return typeFactory.createArrayType(
- typeFactory.createSqlType(SqlTypeName.DOUBLE), -1);
- }
- },
- new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory typeFactory) {
- return typeFactory.createSqlType(SqlTypeName.INTEGER);
- }
- });
+ typeFactory -> typeFactory.createArrayType(
+ typeFactory.createSqlType(SqlTypeName.DOUBLE), -1),
+ typeFactory -> typeFactory.createSqlType(SqlTypeName.INTEGER));
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestTimedCommandGenerator.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestTimedCommandGenerator.java b/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestTimedCommandGenerator.java
index 4c48d35..ef48003 100644
--- a/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestTimedCommandGenerator.java
+++ b/core/src/test/java/org/apache/calcite/test/concurrent/ConcurrentTestTimedCommandGenerator.java
@@ -79,13 +79,9 @@ public class ConcurrentTestTimedCommandGenerator
}
}
- return new Iterable<ConcurrentTestCommand>() {
- public Iterator<ConcurrentTestCommand> iterator() {
- return new TimedIterator<ConcurrentTestCommand>(
- getCommands(threadId),
- endTimeMillis);
- }
- };
+ return () -> new TimedIterator<ConcurrentTestCommand>(
+ getCommands(threadId),
+ endTimeMillis);
}
/**
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java b/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
index 684cfe7..3aa4998 100644
--- a/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
+++ b/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
@@ -19,7 +19,6 @@ package org.apache.calcite.tools;
import org.apache.calcite.DataContext;
import org.apache.calcite.adapter.enumerable.EnumerableConvention;
import org.apache.calcite.adapter.enumerable.EnumerableTableScan;
-import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.QueryProvider;
import org.apache.calcite.linq4j.Queryable;
@@ -36,7 +35,6 @@ import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.plan.volcano.AbstractConverter;
import org.apache.calcite.prepare.CalcitePrepareImpl;
import org.apache.calcite.prepare.Prepare;
-import org.apache.calcite.rel.RelCollation;
import org.apache.calcite.rel.RelDistributionTraitDef;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.TableModify;
@@ -72,7 +70,6 @@ import org.apache.calcite.test.CalciteAssert;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Util;
-import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
@@ -95,55 +92,51 @@ import static org.junit.Assert.fail;
public class FrameworksTest {
@Test public void testOptimize() {
RelNode x =
- Frameworks.withPlanner(new Frameworks.PlannerAction<RelNode>() {
- public RelNode apply(RelOptCluster cluster,
- RelOptSchema relOptSchema,
- SchemaPlus rootSchema) {
- final RelDataTypeFactory typeFactory = cluster.getTypeFactory();
- final Table table = new AbstractTable() {
- public RelDataType getRowType(RelDataTypeFactory typeFactory) {
- final RelDataType stringType =
- typeFactory.createJavaType(String.class);
- final RelDataType integerType =
- typeFactory.createJavaType(Integer.class);
- return typeFactory.builder()
- .add("s", stringType)
- .add("i", integerType)
- .build();
- }
- };
-
- // "SELECT * FROM myTable"
- final RelOptAbstractTable relOptTable = new RelOptAbstractTable(
- relOptSchema,
- "myTable",
- table.getRowType(typeFactory)) {
- };
- final EnumerableTableScan tableRel =
- EnumerableTableScan.create(cluster, relOptTable);
-
- // "WHERE i > 1"
- final RexBuilder rexBuilder = cluster.getRexBuilder();
- final RexNode condition =
- rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN,
- rexBuilder.makeFieldAccess(
- rexBuilder.makeRangeReference(tableRel), "i", true),
- rexBuilder.makeExactLiteral(BigDecimal.ONE));
- final LogicalFilter filter =
- LogicalFilter.create(tableRel, condition);
-
- // Specify that the result should be in Enumerable convention.
- final RelNode rootRel = filter;
- final RelOptPlanner planner = cluster.getPlanner();
- RelTraitSet desiredTraits =
- cluster.traitSet().replace(EnumerableConvention.INSTANCE);
- final RelNode rootRel2 = planner.changeTraits(rootRel,
- desiredTraits);
- planner.setRoot(rootRel2);
-
- // Now, plan.
- return planner.findBestExp();
- }
+ Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> {
+ final RelDataTypeFactory typeFactory = cluster.getTypeFactory();
+ final Table table = new AbstractTable() {
+ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ final RelDataType stringType =
+ typeFactory.createJavaType(String.class);
+ final RelDataType integerType =
+ typeFactory.createJavaType(Integer.class);
+ return typeFactory.builder()
+ .add("s", stringType)
+ .add("i", integerType)
+ .build();
+ }
+ };
+
+ // "SELECT * FROM myTable"
+ final RelOptAbstractTable relOptTable = new RelOptAbstractTable(
+ relOptSchema,
+ "myTable",
+ table.getRowType(typeFactory)) {
+ };
+ final EnumerableTableScan tableRel =
+ EnumerableTableScan.create(cluster, relOptTable);
+
+ // "WHERE i > 1"
+ final RexBuilder rexBuilder = cluster.getRexBuilder();
+ final RexNode condition =
+ rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN,
+ rexBuilder.makeFieldAccess(
+ rexBuilder.makeRangeReference(tableRel), "i", true),
+ rexBuilder.makeExactLiteral(BigDecimal.ONE));
+ final LogicalFilter filter =
+ LogicalFilter.create(tableRel, condition);
+
+ // Specify that the result should be in Enumerable convention.
+ final RelNode rootRel = filter;
+ final RelOptPlanner planner = cluster.getPlanner();
+ RelTraitSet desiredTraits =
+ cluster.traitSet().replace(EnumerableConvention.INSTANCE);
+ final RelNode rootRel2 = planner.changeTraits(rootRel,
+ desiredTraits);
+ planner.setRoot(rootRel2);
+
+ // Now, plan.
+ return planner.findBestExp();
});
String s =
RelOptUtil.dumpPlan("", x, SqlExplainFormat.TEXT,
@@ -271,38 +264,35 @@ public class FrameworksTest {
@Test public void testJdbcValues() throws Exception {
CalciteAssert.that()
.with(CalciteAssert.SchemaSpec.JDBC_SCOTT)
- .doWithConnection(new Function<CalciteConnection, Void>() {
- public Void apply(CalciteConnection conn) {
- try {
- final FrameworkConfig config = Frameworks.newConfigBuilder()
- .defaultSchema(conn.getRootSchema())
- .build();
- final RelBuilder builder = RelBuilder.create(config);
- final RelRunner runner = conn.unwrap(RelRunner.class);
-
- final RelNode values =
- builder.values(new String[]{"a", "b"}, "X", 1, "Y", 2)
- .project(builder.field("a"))
- .build();
-
- // If you run the "values" query before the "scan" query,
- // everything works fine. JdbcValues is never instantiated in any
- // of the 3 queries.
- if (false) {
- runner.prepare(values).executeQuery();
- }
-
- final RelNode scan = builder.scan("JDBC_SCOTT", "EMP").build();
- runner.prepare(scan).executeQuery();
- builder.clear();
-
- // running this after the scott query causes the exception
- RelRunner runner2 = conn.unwrap(RelRunner.class);
- runner2.prepare(values).executeQuery();
- return null;
- } catch (Exception e) {
- throw new RuntimeException(e);
+ .doWithConnection(connection -> {
+ try {
+ final FrameworkConfig config = Frameworks.newConfigBuilder()
+ .defaultSchema(connection.getRootSchema())
+ .build();
+ final RelBuilder builder = RelBuilder.create(config);
+ final RelRunner runner = connection.unwrap(RelRunner.class);
+
+ final RelNode values =
+ builder.values(new String[]{"a", "b"}, "X", 1, "Y", 2)
+ .project(builder.field("a"))
+ .build();
+
+ // If you run the "values" query before the "scan" query,
+ // everything works fine. JdbcValues is never instantiated in any
+ // of the 3 queries.
+ if (false) {
+ runner.prepare(values).executeQuery();
}
+
+ final RelNode scan = builder.scan("JDBC_SCOTT", "EMP").build();
+ runner.prepare(scan).executeQuery();
+ builder.clear();
+
+ // running this after the scott query causes the exception
+ RelRunner runner2 = connection.unwrap(RelRunner.class);
+ runner2.prepare(values).executeQuery();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
});
}
@@ -387,7 +377,7 @@ public class FrameworksTest {
public Statistic getStatistic() {
return Statistics.of(15D,
ImmutableList.of(ImmutableBitSet.of(0)),
- ImmutableList.<RelCollation>of());
+ ImmutableList.of());
}
public Enumerable<Object[]> scan(DataContext root, List<RexNode> filters,
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/tools/PlannerTest.java b/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
index 4150d85..da54ee8 100644
--- a/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
+++ b/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
@@ -60,7 +60,6 @@ import org.apache.calcite.sql.SqlExplainLevel;
import org.apache.calcite.sql.SqlFunctionCategory;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlOperatorTable;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.parser.SqlParseException;
@@ -196,7 +195,7 @@ public class PlannerTest {
SqlOperatorTable opTab =
ChainedSqlOperatorTable.of(stdOpTab,
new ListSqlOperatorTable(
- ImmutableList.<SqlOperator>of(new MyCountAggFunction())));
+ ImmutableList.of(new MyCountAggFunction())));
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final FrameworkConfig config = Frameworks.newConfigBuilder()
.defaultSchema(
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/BitSetsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/BitSetsTest.java b/core/src/test/java/org/apache/calcite/util/BitSetsTest.java
index 4581e9a..fc16c86 100644
--- a/core/src/test/java/org/apache/calcite/util/BitSetsTest.java
+++ b/core/src/test/java/org/apache/calcite/util/BitSetsTest.java
@@ -16,14 +16,13 @@
*/
package org.apache.calcite.util;
-import com.google.common.collect.Maps;
-
import org.junit.Test;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.SortedMap;
+import java.util.TreeMap;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
@@ -192,11 +191,11 @@ public class BitSetsTest {
* Tests the method {@link BitSets#closure(java.util.SortedMap)}
*/
@Test public void testClosure() {
- final SortedMap<Integer, BitSet> empty = Maps.newTreeMap();
+ final SortedMap<Integer, BitSet> empty = new TreeMap<>();
assertThat(BitSets.closure(empty), equalTo(empty));
// Map with an an entry for each position.
- final SortedMap<Integer, BitSet> map = Maps.newTreeMap();
+ final SortedMap<Integer, BitSet> map = new TreeMap<>();
map.put(0, BitSets.of(3));
map.put(1, BitSets.of());
map.put(2, BitSets.of(7));
@@ -217,7 +216,7 @@ public class BitSetsTest {
assertThat("argument modified", map.toString(), equalTo(original));
// Now a similar map with missing entries. Same result.
- final SortedMap<Integer, BitSet> map2 = Maps.newTreeMap();
+ final SortedMap<Integer, BitSet> map2 = new TreeMap<>();
map2.put(0, BitSets.of(3));
map2.put(2, BitSets.of(7));
map2.put(3, BitSets.of(4, 12));
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/ChunkListTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/ChunkListTest.java b/core/src/test/java/org/apache/calcite/util/ChunkListTest.java
index efb1b09..4069c3e 100644
--- a/core/src/test/java/org/apache/calcite/util/ChunkListTest.java
+++ b/core/src/test/java/org/apache/calcite/util/ChunkListTest.java
@@ -17,7 +17,6 @@
package org.apache.calcite.util;
import org.apache.calcite.linq4j.function.Function0;
-import org.apache.calcite.linq4j.function.Function1;
import com.google.common.collect.ImmutableList;
@@ -383,22 +382,7 @@ public class ChunkListTest {
//noinspection unchecked
final Iterable<Pair<Function0<List<Integer>>, String>> factories0 =
Pair.zip(
- Arrays.asList(
- new Function0<List<Integer>>() {
- public List<Integer> apply() {
- return new ArrayList<>();
- }
- },
- new Function0<List<Integer>>() {
- public List<Integer> apply() {
- return new LinkedList<>();
- }
- },
- new Function0<List<Integer>>() {
- public List<Integer> apply() {
- return new ChunkList<>();
- }
- }),
+ Arrays.asList(ArrayList::new, LinkedList::new, ChunkList::new),
Arrays.asList("ArrayList", "LinkedList", "ChunkList-64"));
final List<Pair<Function0<List<Integer>>, String>> factories1 =
new ArrayList<>();
@@ -412,63 +396,52 @@ public class ChunkListTest {
Arrays.asList(100000, 1000000, 10000000),
Arrays.asList("100k", "1m", "10m"));
for (final Pair<Function0<List<Integer>>, String> pair : factories) {
- new Benchmark(
- "add 10m values, " + pair.right,
- new Function1<Benchmark.Statistician, Void>() {
- public Void apply(Benchmark.Statistician statistician) {
- final List<Integer> list = pair.left.apply();
- long start = System.currentTimeMillis();
- for (int i = 0; i < 10000000; i++) {
- list.add(1);
- }
- statistician.record(start);
- return null;
- }
- },
- 10).run();
+ new Benchmark("add 10m values, " + pair.right, statistician -> {
+ final List<Integer> list = pair.left.apply();
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < 10000000; i++) {
+ list.add(1);
+ }
+ statistician.record(start);
+ return null;
+ },
+ 10).run();
}
for (final Pair<Function0<List<Integer>>, String> pair : factories) {
- new Benchmark(
- "iterate over 10m values, " + pair.right,
- new Function1<Benchmark.Statistician, Void>() {
- public Void apply(Benchmark.Statistician statistician) {
- final List<Integer> list = pair.left.apply();
- list.addAll(Collections.nCopies(10000000, 1));
- long start = System.currentTimeMillis();
- int count = 0;
- for (Integer integer : list) {
- count += integer;
- }
- statistician.record(start);
- assert count == 10000000;
- return null;
- }
- },
- 10).run();
+ new Benchmark("iterate over 10m values, " + pair.right, statistician -> {
+ final List<Integer> list = pair.left.apply();
+ list.addAll(Collections.nCopies(10000000, 1));
+ long start = System.currentTimeMillis();
+ int count = 0;
+ for (Integer integer : list) {
+ count += integer;
+ }
+ statistician.record(start);
+ assert count == 10000000;
+ return null;
+ },
+ 10).run();
}
for (final Pair<Function0<List<Integer>>, String> pair : factories) {
for (final Pair<Integer, String> size : sizes) {
if (size.left > 1000000) {
continue;
}
- new Benchmark(
- "delete 10% of " + size.right + " values, " + pair.right,
- new Function1<Benchmark.Statistician, Void>() {
- public Void apply(Benchmark.Statistician statistician) {
- final List<Integer> list = pair.left.apply();
- list.addAll(Collections.nCopies(size.left, 1));
- long start = System.currentTimeMillis();
- int n = 0;
- for (Iterator<Integer> it = list.iterator(); it.hasNext();) {
- Integer integer = it.next();
- Util.discard(integer);
- if (n++ % 10 == 0) {
- it.remove();
- }
+ new Benchmark("delete 10% of " + size.right + " values, " + pair.right,
+ statistician -> {
+ final List<Integer> list = pair.left.apply();
+ list.addAll(Collections.nCopies(size.left, 1));
+ long start = System.currentTimeMillis();
+ int n = 0;
+ for (Iterator<Integer> it = list.iterator(); it.hasNext();) {
+ Integer integer = it.next();
+ Util.discard(integer);
+ if (n++ % 10 == 0) {
+ it.remove();
}
- statistician.record(start);
- return null;
}
+ statistician.record(start);
+ return null;
},
10).run();
}
@@ -479,24 +452,21 @@ public class ChunkListTest {
continue;
}
new Benchmark("get from " + size.right + " values, "
- + (size.left / 1000) + " times, " + pair.right,
- new Function1<Benchmark.Statistician, Void>() {
- public Void apply(Benchmark.Statistician statistician) {
- final List<Integer> list = pair.left.apply();
- list.addAll(Collections.nCopies(size.left, 1));
- final int probeCount = size.left / 1000;
- final Random random = new Random(1);
- long start = System.currentTimeMillis();
- int n = 0;
- for (int i = 0; i < probeCount; i++) {
- n += list.get(random.nextInt(list.size()));
- }
- assert n == probeCount;
- statistician.record(start);
- return null;
- }
- },
- 10).run();
+ + (size.left / 1000) + " times, " + pair.right, statistician -> {
+ final List<Integer> list = pair.left.apply();
+ list.addAll(Collections.nCopies(size.left, 1));
+ final int probeCount = size.left / 1000;
+ final Random random = new Random(1);
+ long start = System.currentTimeMillis();
+ int n = 0;
+ for (int i = 0; i < probeCount; i++) {
+ n += list.get(random.nextInt(list.size()));
+ }
+ assert n == probeCount;
+ statistician.record(start);
+ return null;
+ },
+ 10).run();
}
}
for (final Pair<Function0<List<Integer>>, String> pair : factories) {
@@ -507,40 +477,37 @@ public class ChunkListTest {
new Benchmark(
"add " + size.right
+ " values, delete 10%, insert 20%, get 1%, using "
- + pair.right,
- new Function1<Benchmark.Statistician, Void>() {
- public Void apply(Benchmark.Statistician statistician) {
- final List<Integer> list = pair.left.apply();
- final int probeCount = size.left / 100;
- long start = System.currentTimeMillis();
- list.addAll(Collections.nCopies(size.left, 1));
- final Random random = new Random(1);
- for (Iterator<Integer> it = list.iterator();
- it.hasNext();) {
- Integer integer = it.next();
- Util.discard(integer);
- if (random.nextInt(10) == 0) {
- it.remove();
- }
- }
- for (ListIterator<Integer> it = list.listIterator();
- it.hasNext();) {
- Integer integer = it.next();
- Util.discard(integer);
- if (random.nextInt(5) == 0) {
- it.add(2);
- }
- }
- int n = 0;
- for (int i = 0; i < probeCount; i++) {
- n += list.get(random.nextInt(list.size()));
- }
- assert n > probeCount;
- statistician.record(start);
- return null;
- }
- },
- 10).run();
+ + pair.right, statistician -> {
+ final List<Integer> list = pair.left.apply();
+ final int probeCount = size.left / 100;
+ long start = System.currentTimeMillis();
+ list.addAll(Collections.nCopies(size.left, 1));
+ final Random random = new Random(1);
+ for (Iterator<Integer> it = list.iterator();
+ it.hasNext();) {
+ Integer integer = it.next();
+ Util.discard(integer);
+ if (random.nextInt(10) == 0) {
+ it.remove();
+ }
+ }
+ for (ListIterator<Integer> it = list.listIterator();
+ it.hasNext();) {
+ Integer integer = it.next();
+ Util.discard(integer);
+ if (random.nextInt(5) == 0) {
+ it.add(2);
+ }
+ }
+ int n = 0;
+ for (int i = 0; i < probeCount; i++) {
+ n += list.get(random.nextInt(list.size()));
+ }
+ assert n > probeCount;
+ statistician.record(start);
+ return null;
+ },
+ 10).run();
}
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/ImmutableBitSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/ImmutableBitSetTest.java b/core/src/test/java/org/apache/calcite/util/ImmutableBitSetTest.java
index 680bed4..b8dd2e6 100644
--- a/core/src/test/java/org/apache/calcite/util/ImmutableBitSetTest.java
+++ b/core/src/test/java/org/apache/calcite/util/ImmutableBitSetTest.java
@@ -19,7 +19,6 @@ package org.apache.calcite.util;
import org.apache.calcite.runtime.Utilities;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
import org.junit.Test;
@@ -30,6 +29,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedMap;
+import java.util.TreeMap;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -154,7 +154,7 @@ public class ImmutableBitSetTest {
@Test public void testCompare2() {
final List<ImmutableBitSet> sorted = getSortedList();
- Collections.sort(sorted, ImmutableBitSet.COMPARATOR);
+ sorted.sort(ImmutableBitSet.COMPARATOR);
assertThat(sorted.toString(),
equalTo("[{0, 1, 3}, {0, 1}, {1, 1000}, {1}, {1}, {2, 3}, {}]"));
}
@@ -390,12 +390,12 @@ public class ImmutableBitSetTest {
/** Tests the method
* {@link org.apache.calcite.util.BitSets#closure(java.util.SortedMap)}. */
@Test public void testClosure() {
- final SortedMap<Integer, ImmutableBitSet> empty = Maps.newTreeMap();
+ final SortedMap<Integer, ImmutableBitSet> empty = new TreeMap<>();
assertThat(ImmutableBitSet.closure(empty), equalTo(empty));
// Currently you need an entry for each position, otherwise you get an NPE.
// We should fix that.
- final SortedMap<Integer, ImmutableBitSet> map = Maps.newTreeMap();
+ final SortedMap<Integer, ImmutableBitSet> map = new TreeMap<>();
map.put(0, ImmutableBitSet.of(3));
map.put(1, ImmutableBitSet.of());
map.put(2, ImmutableBitSet.of(7));
@@ -416,7 +416,7 @@ public class ImmutableBitSetTest {
assertThat("argument modified", map.toString(), equalTo(original));
// Now a similar map with missing entries. Same result.
- final SortedMap<Integer, ImmutableBitSet> map2 = Maps.newTreeMap();
+ final SortedMap<Integer, ImmutableBitSet> map2 = new TreeMap<>();
map2.put(0, ImmutableBitSet.of(3));
map2.put(2, ImmutableBitSet.of(7));
map2.put(3, ImmutableBitSet.of(4, 12));
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/PartiallyOrderedSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/PartiallyOrderedSetTest.java b/core/src/test/java/org/apache/calcite/util/PartiallyOrderedSetTest.java
index 8a6a9da..586562b 100644
--- a/core/src/test/java/org/apache/calcite/util/PartiallyOrderedSetTest.java
+++ b/core/src/test/java/org/apache/calcite/util/PartiallyOrderedSetTest.java
@@ -18,8 +18,6 @@ package org.apache.calcite.util;
import org.apache.calcite.test.CalciteAssert;
-import com.google.common.base.Function;
-
import org.junit.Assume;
import org.junit.Test;
@@ -28,9 +26,11 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
+import java.util.function.Function;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
@@ -51,58 +51,44 @@ public class PartiallyOrderedSetTest {
final Random random = new Random(seed);
static final PartiallyOrderedSet.Ordering<String> STRING_SUBSET_ORDERING =
- new PartiallyOrderedSet.Ordering<String>() {
- public boolean lessThan(String e1, String e2) {
- // e1 < e2 if every char in e1 is also in e2
- for (int i = 0; i < e1.length(); i++) {
- if (e2.indexOf(e1.charAt(i)) < 0) {
- return false;
- }
+ (e1, e2) -> {
+ // e1 < e2 if every char in e1 is also in e2
+ for (int i = 0; i < e1.length(); i++) {
+ if (e2.indexOf(e1.charAt(i)) < 0) {
+ return false;
}
- return true;
}
+ return true;
};
- // Integers, ordered by division. Top is 1, its children are primes,
- // etc.
- static final PartiallyOrderedSet.Ordering<Integer> IS_DIVISOR =
- new PartiallyOrderedSet.Ordering<Integer>() {
- public boolean lessThan(Integer e1, Integer e2) {
- return e2 % e1 == 0;
- }
- };
+ /** As an ordering, integers are ordered by division.
+ * Top is 1, its children are primes, etc. */
+ private static boolean isDivisor(int e1, int e2) {
+ return e2 % e1 == 0;
+ }
- // Bottom is 1, parents are primes, etc.
- static final PartiallyOrderedSet.Ordering<Integer> IS_DIVISOR_INVERSE =
- new PartiallyOrderedSet.Ordering<Integer>() {
- public boolean lessThan(Integer e1, Integer e2) {
- return e1 % e2 == 0;
- }
- };
+ /** As an ordering, bottom is 1, parents are primes, etc. */
+ private static boolean isDivisorInverse(Integer e1, Integer e2) {
+ return isDivisor(e2, e1);
+ }
- // Ordered by bit inclusion. E.g. the children of 14 (1110) are
- // 12 (1100), 10 (1010) and 6 (0110).
- static final PartiallyOrderedSet.Ordering<Integer> IS_BIT_SUBSET =
- new PartiallyOrderedSet.Ordering<Integer>() {
- public boolean lessThan(Integer e1, Integer e2) {
- return (e2 & e1) == e2;
- }
- };
+ /** As an ordering, integers are ordered by bit inclusion.
+ * E.g. the children of 14 (1110) are 12 (1100), 10 (1010) and 6 (0110). */
+ private static boolean isBitSubset(int e1, int e2) {
+ return (e2 & e1) == e2;
+ }
- // Ordered by bit inclusion. E.g. the children of 14 (1110) are
- // 12 (1100), 10 (1010) and 6 (0110).
- static final PartiallyOrderedSet.Ordering<Integer> IS_BIT_SUPERSET =
- new PartiallyOrderedSet.Ordering<Integer>() {
- public boolean lessThan(Integer e1, Integer e2) {
- return (e2 & e1) == e1;
- }
- };
+ /** As an ordering, integers are ordered by bit inclusion.
+ * E.g. the parents of 14 (1110) are 12 (1100), 10 (1010) and 6 (0110). */
+ private static boolean isBitSuperset(Integer e1, Integer e2) {
+ return (e2 & e1) == e1;
+ }
@Test public void testPoset() {
String empty = "''";
String abcd = "'abcd'";
- PartiallyOrderedSet<String> poset =
- new PartiallyOrderedSet<String>(STRING_SUBSET_ORDERING);
+ final PartiallyOrderedSet<String> poset =
+ new PartiallyOrderedSet<>(STRING_SUBSET_ORDERING);
assertEquals(0, poset.size());
final StringBuilder buf = new StringBuilder();
@@ -195,8 +181,8 @@ public class PartiallyOrderedSetTest {
}
@Test public void testPosetTricky() {
- PartiallyOrderedSet<String> poset =
- new PartiallyOrderedSet<String>(STRING_SUBSET_ORDERING);
+ final PartiallyOrderedSet<String> poset =
+ new PartiallyOrderedSet<>(STRING_SUBSET_ORDERING);
// A tricky little poset with 4 elements:
// {a <= ab and ac, b < ab, ab, ac}
@@ -213,7 +199,7 @@ public class PartiallyOrderedSetTest {
@Test public void testPosetBits() {
final PartiallyOrderedSet<Integer> poset =
- new PartiallyOrderedSet<Integer>(IS_BIT_SUPERSET);
+ new PartiallyOrderedSet<>(PartiallyOrderedSetTest::isBitSuperset);
poset.add(2112); // {6, 11} i.e. 64 + 2048
poset.add(2240); // {6, 7, 11} i.e. 64 + 128 + 2048
poset.add(2496); // {6, 7, 8, 11} i.e. 64 + 128 + 256 + 2048
@@ -226,7 +212,7 @@ public class PartiallyOrderedSetTest {
@Test public void testPosetBitsLarge() {
final PartiallyOrderedSet<Integer> poset =
- new PartiallyOrderedSet<>(IS_BIT_SUPERSET);
+ new PartiallyOrderedSet<>(PartiallyOrderedSetTest::isBitSuperset);
checkPosetBitsLarge(poset, 30000, 2921, 164782);
}
@@ -234,11 +220,9 @@ public class PartiallyOrderedSetTest {
Assume.assumeTrue("too slow to run every day", CalciteAssert.ENABLE_SLOW);
final int n = 30000;
final PartiallyOrderedSet<Integer> poset =
- new PartiallyOrderedSet<>(IS_BIT_SUPERSET,
- new Function<Integer, Iterable<Integer>>() {
- public Iterable<Integer> apply(Integer input) {
- final int i = input;
- int r = i; // bits not yet cleared
+ new PartiallyOrderedSet<>(PartiallyOrderedSetTest::isBitSuperset,
+ (Function<Integer, Iterable<Integer>>) i -> {
+ int r = Objects.requireNonNull(i); // bits not yet cleared
final List<Integer> list = new ArrayList<>();
for (int z = 1; r != 0; z <<= 1) {
if ((i & z) != 0) {
@@ -247,11 +231,9 @@ public class PartiallyOrderedSetTest {
}
}
return list;
- }
- },
- new Function<Integer, Iterable<Integer>>() {
- public Iterable<Integer> apply(Integer input) {
- final int i = input;
+ },
+ i -> {
+ Objects.requireNonNull(i);
final List<Integer> list = new ArrayList<>();
for (int z = 1; z <= n; z <<= 1) {
if ((i & z) == 0) {
@@ -259,8 +241,7 @@ public class PartiallyOrderedSetTest {
}
}
return list;
- }
- });
+ });
checkPosetBitsLarge(poset, n, 2921, 11961);
}
@@ -286,7 +267,7 @@ public class PartiallyOrderedSetTest {
@Test public void testPosetBitsRemoveParent() {
final PartiallyOrderedSet<Integer> poset =
- new PartiallyOrderedSet<Integer>(IS_BIT_SUPERSET);
+ new PartiallyOrderedSet<>(PartiallyOrderedSetTest::isBitSuperset);
poset.add(66); // {bit 2, bit 6}
poset.add(68); // {bit 3, bit 6}
poset.add(72); // {bit 4, bit 6}
@@ -298,13 +279,14 @@ public class PartiallyOrderedSetTest {
@Test public void testDivisorPoset() {
PartiallyOrderedSet<Integer> integers =
- new PartiallyOrderedSet<Integer>(IS_DIVISOR, range(1, 1000));
+ new PartiallyOrderedSet<>(PartiallyOrderedSetTest::isDivisor,
+ range(1, 1000));
assertEquals(
"[1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60]",
- new TreeSet<Integer>(integers.getDescendants(120)).toString());
+ new TreeSet<>(integers.getDescendants(120)).toString());
assertEquals(
"[240, 360, 480, 600, 720, 840, 960]",
- new TreeSet<Integer>(integers.getAncestors(120)).toString());
+ new TreeSet<>(integers.getAncestors(120)).toString());
assertTrue(integers.getDescendants(1).isEmpty());
assertEquals(
998,
@@ -313,14 +295,15 @@ public class PartiallyOrderedSetTest {
}
@Test public void testDivisorSeries() {
- checkPoset(IS_DIVISOR, DEBUG, range(1, SCALE * 3), false);
+ checkPoset(PartiallyOrderedSetTest::isDivisor, DEBUG, range(1, SCALE * 3),
+ false);
}
@Test public void testDivisorRandom() {
boolean ok = false;
try {
- checkPoset(
- IS_DIVISOR, DEBUG, random(random, SCALE, SCALE * 3), false);
+ checkPoset(PartiallyOrderedSetTest::isDivisor, DEBUG,
+ random(random, SCALE, SCALE * 3), false);
ok = true;
} finally {
if (!ok) {
@@ -332,8 +315,8 @@ public class PartiallyOrderedSetTest {
@Test public void testDivisorRandomWithRemoval() {
boolean ok = false;
try {
- checkPoset(
- IS_DIVISOR, DEBUG, random(random, SCALE, SCALE * 3), true);
+ checkPoset(PartiallyOrderedSetTest::isDivisor, DEBUG,
+ random(random, SCALE, SCALE * 3), true);
ok = true;
} finally {
if (!ok) {
@@ -343,14 +326,14 @@ public class PartiallyOrderedSetTest {
}
@Test public void testDivisorInverseSeries() {
- checkPoset(IS_DIVISOR_INVERSE, DEBUG, range(1, SCALE * 3), false);
+ checkPoset(PartiallyOrderedSetTest::isDivisorInverse, DEBUG,
+ range(1, SCALE * 3), false);
}
@Test public void testDivisorInverseRandom() {
boolean ok = false;
try {
- checkPoset(
- IS_DIVISOR_INVERSE, DEBUG, random(random, SCALE, SCALE * 3),
+ checkPoset(PartiallyOrderedSetTest::isDivisorInverse, DEBUG, random(random, SCALE, SCALE * 3),
false);
ok = true;
} finally {
@@ -363,8 +346,7 @@ public class PartiallyOrderedSetTest {
@Test public void testDivisorInverseRandomWithRemoval() {
boolean ok = false;
try {
- checkPoset(
- IS_DIVISOR_INVERSE, DEBUG, random(random, SCALE, SCALE * 3),
+ checkPoset(PartiallyOrderedSetTest::isDivisorInverse, DEBUG, random(random, SCALE, SCALE * 3),
true);
ok = true;
} finally {
@@ -375,14 +357,14 @@ public class PartiallyOrderedSetTest {
}
@Test public void testSubsetSeries() {
- checkPoset(IS_BIT_SUBSET, DEBUG, range(1, SCALE / 2), false);
+ checkPoset(PartiallyOrderedSetTest::isBitSubset, DEBUG, range(1, SCALE / 2), false);
}
@Test public void testSubsetRandom() {
boolean ok = false;
try {
- checkPoset(
- IS_BIT_SUBSET, DEBUG, random(random, SCALE / 4, SCALE), false);
+ checkPoset(PartiallyOrderedSetTest::isBitSubset, DEBUG,
+ random(random, SCALE / 4, SCALE), false);
ok = true;
} finally {
if (!ok) {
@@ -404,7 +386,7 @@ public class PartiallyOrderedSetTest {
Iterable<Integer> generator,
boolean remove) {
final PartiallyOrderedSet<Integer> poset =
- new PartiallyOrderedSet<Integer>(ordering);
+ new PartiallyOrderedSet<>(ordering);
int n = 0;
int z = 0;
if (debug) {
@@ -464,7 +446,7 @@ public class PartiallyOrderedSetTest {
private static Iterable<Integer> random(
Random random, final int size, final int max) {
- final Set<Integer> set = new LinkedHashSet<Integer>();
+ final Set<Integer> set = new LinkedHashSet<>();
while (set.size() < size) {
set.add(random.nextInt(max) + 1);
}
@@ -472,9 +454,7 @@ public class PartiallyOrderedSetTest {
}
private static void assertEqualsList(String expected, List<String> ss) {
- assertEquals(
- expected,
- new TreeSet<String>(ss).toString());
+ assertEquals(expected, new TreeSet<>(ss).toString());
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/PermutationTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/PermutationTestCase.java b/core/src/test/java/org/apache/calcite/util/PermutationTestCase.java
index 75c78c0..2fe6ed2 100644
--- a/core/src/test/java/org/apache/calcite/util/PermutationTestCase.java
+++ b/core/src/test/java/org/apache/calcite/util/PermutationTestCase.java
@@ -16,7 +16,6 @@
*/
package org.apache.calcite.util;
-
import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.type.RelDataType;
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/PrecedenceClimbingParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/PrecedenceClimbingParserTest.java b/core/src/test/java/org/apache/calcite/util/PrecedenceClimbingParserTest.java
index 3fbeac4..0988430 100644
--- a/core/src/test/java/org/apache/calcite/util/PrecedenceClimbingParserTest.java
+++ b/core/src/test/java/org/apache/calcite/util/PrecedenceClimbingParserTest.java
@@ -134,17 +134,12 @@ public class PrecedenceClimbingParserTest {
.infix("and", 2, true)
.atom("price")
.special("between", 3, 3,
- new PrecedenceClimbingParser.Special() {
- public PrecedenceClimbingParser.Result apply(
- PrecedenceClimbingParser parser,
- PrecedenceClimbingParser.SpecialOp op) {
- return new PrecedenceClimbingParser.Result(op.previous,
+ (parser, op) ->
+ new PrecedenceClimbingParser.Result(op.previous,
op.next.next.next,
parser.call(op,
ImmutableList.of(op.previous, op.next,
- op.next.next.next)));
- }
- })
+ op.next.next.next))))
.atom("1")
.infix("+", 5, true)
.atom("2")
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/Smalls.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/Smalls.java b/core/src/test/java/org/apache/calcite/util/Smalls.java
index bffeca6..46ae6a3 100644
--- a/core/src/test/java/org/apache/calcite/util/Smalls.java
+++ b/core/src/test/java/org/apache/calcite/util/Smalls.java
@@ -27,14 +27,11 @@ import org.apache.calcite.linq4j.Linq4j;
import org.apache.calcite.linq4j.QueryProvider;
import org.apache.calcite.linq4j.Queryable;
import org.apache.calcite.linq4j.function.Deterministic;
-import org.apache.calcite.linq4j.function.Function1;
-import org.apache.calcite.linq4j.function.Function2;
import org.apache.calcite.linq4j.function.Parameter;
import org.apache.calcite.linq4j.function.SemiStrict;
import org.apache.calcite.linq4j.tree.Types;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.runtime.SqlFunctions;
import org.apache.calcite.schema.QueryableTable;
@@ -67,7 +64,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-
/**
* Holder for various classes and functions used in tests as user-defined
* functions and so forth.
@@ -303,11 +299,7 @@ public class Smalls {
public <T> Queryable<T> asQueryable(QueryProvider queryProvider,
SchemaPlus schema, String tableName) {
final Enumerable<Integer> enumerable =
- a.select(new Function1<Object[], Integer>() {
- public Integer apply(Object[] a0) {
- return offset + ((Integer) a0[0]);
- }
- });
+ a.select(a0 -> offset + ((Integer) a0[0]));
//noinspection unchecked
return (Queryable) enumerable.asQueryable();
}
@@ -330,11 +322,7 @@ public class Smalls {
public <T> Queryable<T> asQueryable(QueryProvider queryProvider,
SchemaPlus schema, String tableName) {
final Enumerable<Integer> enumerable =
- a.zip(b, new Function2<Object[], IntString, Integer>() {
- public Integer apply(Object[] v0, IntString v1) {
- return ((Integer) v0[1]) + v1.n + offset;
- }
- });
+ a.zip(b, (v0, v1) -> ((Integer) v0[1]) + v1.n + offset);
//noinspection unchecked
return (Queryable) enumerable.asQueryable();
}
@@ -342,39 +330,26 @@ public class Smalls {
}
public static TranslatableTable view(String s) {
- return new ViewTable(Object.class,
- new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory typeFactory) {
- return typeFactory.builder().add("c", SqlTypeName.INTEGER)
- .build();
- }
- }, "values (1), (3), " + s, ImmutableList.<String>of(), Arrays.asList("view"));
+ return new ViewTable(Object.class, typeFactory ->
+ typeFactory.builder().add("c", SqlTypeName.INTEGER).build(),
+ "values (1), (3), " + s, ImmutableList.of(), Arrays.asList("view"));
}
public static TranslatableTable strView(String s) {
- return new ViewTable(Object.class,
- new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory typeFactory) {
- return typeFactory.builder().add("c", SqlTypeName.VARCHAR, 100)
- .build();
- }
- }, "values (" + CalciteSqlDialect.DEFAULT.quoteStringLiteral(s) + ")",
- ImmutableList.<String>of(), Arrays.asList("view"));
+ return new ViewTable(Object.class, typeFactory ->
+ typeFactory.builder().add("c", SqlTypeName.VARCHAR, 100).build(),
+ "values (" + CalciteSqlDialect.DEFAULT.quoteStringLiteral(s) + ")",
+ ImmutableList.of(), Arrays.asList("view"));
}
public static TranslatableTable str(Object o, Object p) {
assertThat(RexLiteral.validConstant(o, Litmus.THROW), is(true));
assertThat(RexLiteral.validConstant(p, Litmus.THROW), is(true));
- return new ViewTable(Object.class,
- new RelProtoDataType() {
- public RelDataType apply(RelDataTypeFactory typeFactory) {
- return typeFactory.builder().add("c", SqlTypeName.VARCHAR, 100)
- .build();
- }
- },
+ return new ViewTable(Object.class, typeFactory ->
+ typeFactory.builder().add("c", SqlTypeName.VARCHAR, 100).build(),
"values " + CalciteSqlDialect.DEFAULT.quoteStringLiteral(o.toString())
+ ", " + CalciteSqlDialect.DEFAULT.quoteStringLiteral(p.toString()),
- ImmutableList.<String>of(), Arrays.asList("view"));
+ ImmutableList.of(), Arrays.asList("view"));
}
/** Class with int and String fields. */
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/UtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/UtilTest.java b/core/src/test/java/org/apache/calcite/util/UtilTest.java
index 4560fd5..e9159a9 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -23,7 +23,6 @@ import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.calcite.linq4j.Linq4j;
import org.apache.calcite.linq4j.Ord;
-import org.apache.calcite.linq4j.function.Function1;
import org.apache.calcite.linq4j.function.Parameter;
import org.apache.calcite.runtime.ConsList;
import org.apache.calcite.runtime.FlatLists;
@@ -37,7 +36,6 @@ import org.apache.calcite.sql.util.SqlString;
import org.apache.calcite.test.DiffTestCase;
import org.apache.calcite.test.Matchers;
-import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultiset;
import com.google.common.collect.ImmutableSortedSet;
@@ -70,17 +68,19 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NavigableSet;
import java.util.Properties;
import java.util.Random;
+import java.util.RandomAccess;
import java.util.Set;
import java.util.SortedSet;
import java.util.TimeZone;
import java.util.TreeSet;
-import javax.annotation.Nullable;
+import java.util.function.Function;
import static org.apache.calcite.test.Matchers.isLinux;
@@ -455,7 +455,7 @@ public class UtilTest {
// ok
}
- final List<String> a = ConsList.of("a", ImmutableList.<String>of());
+ final List<String> a = ConsList.of("a", ImmutableList.of());
assertThat(a.size(), is(1));
assertThat(a, is(Collections.singletonList("a")));
}
@@ -1419,11 +1419,11 @@ public class UtilTest {
checkCompositeMap(beatles, map);
map = CompositeMap.of(
- beatleMap, Collections.<String, Integer>emptyMap());
+ beatleMap, Collections.emptyMap());
checkCompositeMap(beatles, map);
map = CompositeMap.of(
- Collections.<String, Integer>emptyMap(), beatleMap);
+ Collections.emptyMap(), beatleMap);
checkCompositeMap(beatles, map);
map = CompositeMap.of(beatleMap, beatleMap);
@@ -1471,7 +1471,7 @@ public class UtilTest {
} catch (NullPointerException e) {
// ok
}
- assertThat(Util.commaList(ImmutableList.<Object>of()), equalTo(""));
+ assertThat(Util.commaList(ImmutableList.of()), equalTo(""));
assertThat(Util.commaList(ImmutableList.of(1)), equalTo("1"));
assertThat(Util.commaList(ImmutableList.of(2, 3)), equalTo("2, 3"));
assertThat(Util.commaList(Arrays.asList(2, null, 3)),
@@ -1503,28 +1503,25 @@ public class UtilTest {
final int zMax = 100;
for (int i = 0; i < 30; i++) {
final int size = i;
- new Benchmark("isDistinct " + i + " (set)",
- new Function1<Benchmark.Statistician, Void>() {
- public Void apply(Benchmark.Statistician statistician) {
- final Random random = new Random(0);
- final List<List<Integer>> lists = new ArrayList<List<Integer>>();
- for (int z = 0; z < zMax; z++) {
- final List<Integer> list = new ArrayList<Integer>();
- for (int k = 0; k < size; k++) {
- list.add(random.nextInt(size * size));
- }
- lists.add(list);
- }
- long nanos = System.nanoTime();
- int n = 0;
- for (int j = 0; j < limit; j++) {
- n += Util.firstDuplicate(lists.get(j % zMax));
- }
- statistician.record(nanos);
- Util.discard(n);
- return null;
- }
- },
+ new Benchmark("isDistinct " + i + " (set)", statistician -> {
+ final Random random = new Random(0);
+ final List<List<Integer>> lists = new ArrayList<List<Integer>>();
+ for (int z = 0; z < zMax; z++) {
+ final List<Integer> list = new ArrayList<Integer>();
+ for (int k = 0; k < size; k++) {
+ list.add(random.nextInt(size * size));
+ }
+ lists.add(list);
+ }
+ long nanos = System.nanoTime();
+ int n = 0;
+ for (int j = 0; j < limit; j++) {
+ n += Util.firstDuplicate(lists.get(j % zMax));
+ }
+ statistician.record(nanos);
+ Util.discard(n);
+ return null;
+ },
5).run();
}
}
@@ -1622,16 +1619,14 @@ public class UtilTest {
treeSet2.addAll(treeSet);
assertThat(treeSet2.size(), equalTo(3));
- final Comparator<String> comparator = new Comparator<String>() {
- public int compare(String o1, String o2) {
- String u1 = o1.toUpperCase(Locale.ROOT);
- String u2 = o2.toUpperCase(Locale.ROOT);
- int c = u1.compareTo(u2);
- if (c == 0) {
- c = o1.compareTo(o2);
- }
- return c;
+ final Comparator<String> comparator = (o1, o2) -> {
+ String u1 = o1.toUpperCase(Locale.ROOT);
+ String u2 = o2.toUpperCase(Locale.ROOT);
+ int c = u1.compareTo(u2);
+ if (c == 0) {
+ c = o1.compareTo(o2);
}
+ return c;
};
final TreeSet<String> treeSet3 = new TreeSet<String>(comparator);
treeSet3.addAll(treeSet);
@@ -1702,24 +1697,14 @@ public class UtilTest {
isA((Class) ImmutableList.class));
// list with no nulls uses ImmutableList
- final Iterable<String> abc =
- new Iterable<String>() {
- public Iterator<String> iterator() {
- return abcList.iterator();
- }
- };
+ final Iterable<String> abc = abcList::iterator;
assertThat(ImmutableNullableList.copyOf(abc),
isA((Class) ImmutableList.class));
assertThat(ImmutableNullableList.copyOf(abc), equalTo(abcList));
// list with no nulls uses ImmutableList
final List<String> ab0cList = Arrays.asList("a", "b", null, "c");
- final Iterable<String> ab0c =
- new Iterable<String>() {
- public Iterator<String> iterator() {
- return ab0cList.iterator();
- }
- };
+ final Iterable<String> ab0c = ab0cList::iterator;
assertThat(ImmutableNullableList.copyOf(ab0c),
not(isA((Class) ImmutableList.class)));
assertThat(ImmutableNullableList.copyOf(ab0c), equalTo(ab0cList));
@@ -1850,12 +1835,8 @@ public class UtilTest {
@Test public void testAsIndexView() {
final List<String> values = Lists.newArrayList("abCde", "X", "y");
- final Map<String, String> map = Util.asIndexMap(values,
- new Function<String, String>() {
- public String apply(@Nullable String input) {
- return input.toUpperCase(Locale.ROOT);
- }
- });
+ final Map<String, String> map =
+ Util.asIndexMapJ(values, input -> input.toUpperCase(Locale.ROOT));
assertThat(map.size(), equalTo(values.size()));
assertThat(map.get("X"), equalTo("X"));
assertThat(map.get("Y"), equalTo("y"));
@@ -2149,12 +2130,7 @@ public class UtilTest {
assertThat("x", is("x"));
assertThat(is("x").matches("x"), is(true));
assertThat(is("X").matches("x"), is(false));
- final Function<String, String> toUpper =
- new Function<String, String>() {
- public String apply(String input) {
- return input.toUpperCase(Locale.ROOT);
- }
- };
+ final Function<String, String> toUpper = s -> s.toUpperCase(Locale.ROOT);
assertThat(Matchers.compose(is("A"), toUpper).matches("a"), is(true));
assertThat(Matchers.compose(is("A"), toUpper).matches("A"), is(true));
assertThat(Matchers.compose(is("a"), toUpper).matches("A"), is(false));
@@ -2182,6 +2158,23 @@ public class UtilTest {
assertThat(isLinux("x\r\ny").matches("x\ny"), is(false));
}
+ /** Tests {@link Util#transform(List, java.util.function.Function)}. */
+ @Test public void testTransform() {
+ final List<String> beatles =
+ Arrays.asList("John", "Paul", "George", "Ringo");
+ final List<String> empty = Collections.emptyList();
+ assertThat(Util.transform(beatles, s -> s.toUpperCase(Locale.ROOT)),
+ is(Arrays.asList("JOHN", "PAUL", "GEORGE", "RINGO")));
+ assertThat(Util.transform(empty, s -> s.toUpperCase(Locale.ROOT)), is(empty));
+ assertThat(Util.transform(beatles, String::length),
+ is(Arrays.asList(4, 4, 6, 5)));
+ assertThat(Util.transform(beatles, String::length),
+ instanceOf(RandomAccess.class));
+ final List<String> beatles2 = new LinkedList<>(beatles);
+ assertThat(Util.transform(beatles2, String::length),
+ not(instanceOf(RandomAccess.class)));
+ }
+
static String mismatchDescription(Matcher m, Object item) {
final StringDescription d = new StringDescription();
m.describeMismatch(item, d);
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java b/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java
index 6724ffc..483a704 100644
--- a/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java
+++ b/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java
@@ -221,7 +221,7 @@ public class DirectedGraphTest {
// +- E - F
DefaultDirectedGraph<String, DefaultEdge> graph = createDag();
assertThat(new CycleDetector<String, DefaultEdge>(graph).findCycles(),
- CoreMatchers.<Set<String>>equalTo(ImmutableSet.<String>of()));
+ CoreMatchers.equalTo(ImmutableSet.of()));
// Add cycle C-D-E-C
//
@@ -232,8 +232,8 @@ public class DirectedGraphTest {
// \_____/
graph.addEdge("D", "E");
assertThat(new CycleDetector<String, DefaultEdge>(graph).findCycles(),
- CoreMatchers.<Set<String>>equalTo(
- ImmutableSet.<String>of("C", "D", "E", "F")));
+ CoreMatchers.equalTo(
+ ImmutableSet.of("C", "D", "E", "F")));
// Add another cycle, D-C-D in addition to C-D-E-C.
// __
@@ -245,8 +245,8 @@ public class DirectedGraphTest {
// \_____/
graph.addEdge("D", "C");
assertThat(new CycleDetector<String, DefaultEdge>(graph).findCycles(),
- CoreMatchers.<Set<String>>equalTo(
- ImmutableSet.<String>of("C", "D", "E", "F")));
+ CoreMatchers.equalTo(
+ ImmutableSet.of("C", "D", "E", "F")));
graph.removeEdge("D", "E");
graph.removeEdge("D", "C");
@@ -262,8 +262,8 @@ public class DirectedGraphTest {
// Detected cycle contains "D", which is downstream from the cycle but not
// in the cycle. Not sure whether that is correct.
assertThat(new CycleDetector<String, DefaultEdge>(graph).findCycles(),
- CoreMatchers.<Set<String>>equalTo(
- ImmutableSet.<String>of("B", "C", "D")));
+ CoreMatchers.equalTo(
+ ImmutableSet.of("B", "C", "D")));
// Add single-node cycle, C-C
//
@@ -275,13 +275,13 @@ public class DirectedGraphTest {
graph.removeEdge("C", "B");
graph.addEdge("C", "C");
assertThat(new CycleDetector<String, DefaultEdge>(graph).findCycles(),
- CoreMatchers.<Set<String>>equalTo(
- ImmutableSet.<String>of("C", "D")));
+ CoreMatchers.equalTo(
+ ImmutableSet.of("C", "D")));
// Empty graph is not cyclic.
graph.removeAllVertices(graph.vertexSet());
assertThat(new CycleDetector<String, DefaultEdge>(graph).findCycles(),
- CoreMatchers.<Set<String>>equalTo(ImmutableSet.<String>of()));
+ CoreMatchers.equalTo(ImmutableSet.of()));
}
/** Unit test for
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java b/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java
index 2155294..e9817fb 100644
--- a/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java
+++ b/core/src/test/java/org/apache/calcite/util/mapping/MappingTest.java
@@ -204,7 +204,7 @@ public class MappingTest {
assertThat(mapping.inverse().toString(), equalTo("[1, 2, 3, 0]"));
// empty is OK
- final Mapping empty = Mappings.bijection(Collections.<Integer>emptyList());
+ final Mapping empty = Mappings.bijection(Collections.emptyList());
assertThat(empty.size(), equalTo(0));
assertThat(empty.iterator().hasNext(), equalTo(false));
assertThat(empty.toString(), equalTo("[]"));
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/druid/src/main/java/org/apache/calcite/adapter/druid/DefaultDimensionSpec.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DefaultDimensionSpec.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DefaultDimensionSpec.java
index 28f99da..446b26b 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DefaultDimensionSpec.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DefaultDimensionSpec.java
@@ -17,9 +17,9 @@
package org.apache.calcite.adapter.druid;
import com.fasterxml.jackson.core.JsonGenerator;
-import com.google.common.base.Preconditions;
import java.io.IOException;
+import java.util.Objects;
/**
* Default implementation of DimensionSpec.
@@ -34,8 +34,8 @@ public class DefaultDimensionSpec implements DimensionSpec {
private final DruidType outputType;
public DefaultDimensionSpec(String dimension, String outputName, DruidType outputType) {
- this.dimension = Preconditions.checkNotNull(dimension);
- this.outputName = Preconditions.checkNotNull(outputName);
+ this.dimension = Objects.requireNonNull(dimension);
+ this.outputName = Objects.requireNonNull(outputName);
this.outputType = outputType == null ? DruidType.STRING : outputType;
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
index 6d57438..175a16d 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidConnectionImpl.java
@@ -37,7 +37,6 @@ import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -56,6 +55,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ArrayBlockingQueue;
@@ -84,8 +84,8 @@ class DruidConnectionImpl implements DruidConnection {
}
DruidConnectionImpl(String url, String coordinatorUrl) {
- this.url = Preconditions.checkNotNull(url);
- this.coordinatorUrl = Preconditions.checkNotNull(coordinatorUrl);
+ this.url = Objects.requireNonNull(url);
+ this.coordinatorUrl = Objects.requireNonNull(coordinatorUrl);
}
/** Executes a query request.
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/druid/src/main/java/org/apache/calcite/adapter/druid/DruidDateTimeUtils.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidDateTimeUtils.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidDateTimeUtils.java
index 20da334..efaab36 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidDateTimeUtils.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidDateTimeUtils.java
@@ -29,7 +29,6 @@ import org.apache.calcite.util.TimestampString;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.trace.CalciteTrace;
-import com.google.common.base.Function;
import com.google.common.collect.BoundType;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@@ -83,29 +82,26 @@ public class DruidDateTimeUtils {
protected static List<Interval> toInterval(
List<Range<Long>> ranges) {
- List<Interval> intervals = Lists.transform(ranges,
- new Function<Range<Long>, Interval>() {
- public Interval apply(Range<Long> range) {
- if (!range.hasLowerBound() && !range.hasUpperBound()) {
- return DruidTable.DEFAULT_INTERVAL;
- }
- long start = range.hasLowerBound()
- ? range.lowerEndpoint().longValue()
- : DruidTable.DEFAULT_INTERVAL.getStartMillis();
- long end = range.hasUpperBound()
- ? range.upperEndpoint().longValue()
- : DruidTable.DEFAULT_INTERVAL.getEndMillis();
- if (range.hasLowerBound()
- && range.lowerBoundType() == BoundType.OPEN) {
- start++;
- }
- if (range.hasUpperBound()
- && range.upperBoundType() == BoundType.CLOSED) {
- end++;
- }
- return new Interval(start, end, ISOChronology.getInstanceUTC());
- }
- });
+ List<Interval> intervals = Lists.transform(ranges, range -> {
+ if (!range.hasLowerBound() && !range.hasUpperBound()) {
+ return DruidTable.DEFAULT_INTERVAL;
+ }
+ long start = range.hasLowerBound()
+ ? range.lowerEndpoint().longValue()
+ : DruidTable.DEFAULT_INTERVAL.getStartMillis();
+ long end = range.hasUpperBound()
+ ? range.upperEndpoint().longValue()
+ : DruidTable.DEFAULT_INTERVAL.getEndMillis();
+ if (range.hasLowerBound()
+ && range.lowerBoundType() == BoundType.OPEN) {
+ start++;
+ }
+ if (range.hasUpperBound()
+ && range.upperBoundType() == BoundType.CLOSED) {
+ end++;
+ }
+ return new Interval(start, end, ISOChronology.getInstanceUTC());
+ });
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Converted time ranges " + ranges + " to interval " + intervals);
}
@@ -129,7 +125,7 @@ public class DruidDateTimeUtils {
case OR: {
RexCall call = (RexCall) node;
- List<Range<Long>> intervals = Lists.newArrayList();
+ List<Range<Long>> intervals = new ArrayList<>();
for (RexNode child : call.getOperands()) {
List<Range<Long>> extracted =
extractRanges(child, withNot);