You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/11/14 22:32:25 UTC
[17/58] [abbrv] [partial] incubator-calcite git commit: [CALCITE-306]
Standardize code style for "import package.*; "
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
index d8ebe27..ad86773 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
@@ -14,23 +14,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
-
-import java.util.*;
-
-import org.eigenbase.reltype.*;
-import org.eigenbase.sql.advise.*;
-import org.eigenbase.sql.fun.*;
-import org.eigenbase.sql.parser.*;
-import org.eigenbase.sql.type.*;
-import org.eigenbase.sql.validate.*;
-import org.eigenbase.test.*;
-import org.eigenbase.util.*;
+package org.apache.calcite.sql.test;
+
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.sql.advise.SqlAdvisor;
+import org.apache.calcite.sql.advise.SqlAdvisorValidator;
+import org.apache.calcite.sql.advise.SqlSimpleParser;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserUtil;
+import org.apache.calcite.sql.type.SqlTypeFactoryImpl;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlMoniker;
+import org.apache.calcite.sql.validate.SqlMonikerType;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorWithHints;
+import org.apache.calcite.test.MockCatalogReader;
+import org.apache.calcite.test.SqlValidatorTestCase;
import org.junit.Assert;
import org.junit.Test;
-import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
/**
* Concrete child class of {@link SqlValidatorTestCase}, containing unit tests
@@ -285,7 +298,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
private static final String EMPNO_EMP =
"COLUMN(EMPNO)\n"
- + "TABLE(EMP)\n";
+ + "TABLE(EMP)\n";
//~ Constructors -----------------------------------------------------------
@@ -434,8 +447,8 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
&& (expectedList.size() == uniqueResults.values().size()))) {
fail(
"SqlAdvisorTest: completion hints results not as salesTables:\n"
- + uniqueResults.values() + "\nExpected:\n"
- + expectedList);
+ + uniqueResults.values() + "\nExpected:\n"
+ + expectedList);
}
}
@@ -464,8 +477,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
return buf.toString();
}
- @Override
- public SqlTester getTester() {
+ @Override public SqlTester getTester() {
return new SqlTesterImpl(new AdvisorTesterFactory());
}
@@ -518,7 +530,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
// from
sql =
"select a.empno, b.deptno from ^dummy a join sales.dummy b "
- + "on a.deptno=b.deptno where empno=1";
+ + "on a.deptno=b.deptno where empno=1";
assertHint(sql, getFromKeywords(), SCHEMAS, getSalesTables());
// from
@@ -530,7 +542,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
// join
sql =
"select a.empno, b.deptno from dummy a join ^sales.dummy b "
- + "on a.deptno=b.deptno where empno=1";
+ + "on a.deptno=b.deptno where empno=1";
assertHint(sql, getFromKeywords(), SCHEMAS, getSalesTables());
sql = "select a.empno, b.deptno from dummy a join sales.^";
@@ -556,27 +568,27 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on ^a.deptno=b.dummy where empno=1";
+ + "on ^a.deptno=b.dummy where empno=1";
assertHint(sql, AB_TABLES, EXPR_KEYWORDS); // on left
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.^";
+ + "on a.^";
assertComplete(sql, EMP_COLUMNS); // on left
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=^b.dummy where empno=1";
+ + "on a.deptno=^b.dummy where empno=1";
assertHint(sql, EXPR_KEYWORDS, AB_TABLES); // on right
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=b.^ where empno=1";
+ + "on a.deptno=b.^ where empno=1";
assertComplete(sql, DEPT_COLUMNS); // on right
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=b.^";
+ + "on a.deptno=b.^";
assertComplete(sql, DEPT_COLUMNS); // on right
}
@@ -585,31 +597,31 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
sql =
"select a.empno, b.deptno from sales.emp a, sales.dept b "
- + "where b.deptno=^a.dummy";
+ + "where b.deptno=^a.dummy";
assertHint(sql, AB_TABLES, EXPR_KEYWORDS); // where list
sql =
"select a.empno, b.deptno from sales.emp a, sales.dept b "
- + "where b.deptno=a.^";
+ + "where b.deptno=a.^";
assertComplete(sql, EMP_COLUMNS); // where list
// hints contain no columns, only table aliases, because there are >1
// aliases
sql =
"select a.empno, b.deptno from sales.emp a, sales.dept b "
- + "where ^dummy=1";
+ + "where ^dummy=1";
assertHint(sql, AB_TABLES, EXPR_KEYWORDS); // where list
sql =
"select a.empno, b.deptno from sales.emp a, sales.dept b "
- + "where ^";
+ + "where ^";
assertComplete(sql, AB_TABLES, EXPR_KEYWORDS); // where list
// If there's only one table alias, we allow both the alias and the
// unqualified columns
assertComplete(
"select a.empno, a.deptno from sales.emp a "
- + "where ^",
+ + "where ^",
A_TABLE,
EMP_COLUMNS,
EXPR_KEYWORDS);
@@ -620,27 +632,27 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=b.deptno where ^dummy=1";
+ + "on a.deptno=b.deptno where ^dummy=1";
assertHint(sql, EXPR_KEYWORDS, AB_TABLES); // where list
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=b.deptno where ^";
+ + "on a.deptno=b.deptno where ^";
assertComplete(sql, EXPR_KEYWORDS, AB_TABLES); // where list
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=b.deptno where ^a.dummy=1";
+ + "on a.deptno=b.deptno where ^a.dummy=1";
assertHint(sql, EXPR_KEYWORDS, AB_TABLES); // where list
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=b.deptno where a.^";
+ + "on a.deptno=b.deptno where a.^";
assertComplete(sql, EMP_COLUMNS);
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=b.deptno where a.empno ^ ";
+ + "on a.deptno=b.deptno where a.empno ^ ";
assertComplete(sql, PREDICATE_KEYWORDS, WHERE_KEYWORDS);
}
@@ -649,7 +661,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
sql =
"select ^dummy, b.dummy from sales.emp a join sales.dept b "
- + "on a.deptno=b.deptno where empno=1";
+ + "on a.deptno=b.deptno where empno=1";
assertHint(
sql, getSelectKeywords(), EXPR_KEYWORDS, AB_TABLES, SETOPS,
FETCH_OFFSET);
@@ -679,7 +691,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
sql =
"select dummy, ^b.dummy from sales.emp a join sales.dept b "
- + "on a.deptno=b.deptno where empno=1";
+ + "on a.deptno=b.deptno where empno=1";
assertHint(sql, EXPR_KEYWORDS, STAR_KEYWORD, AB_TABLES);
sql = "select dummy, b.^ from sales.emp a join sales.dept b on true";
@@ -716,9 +728,9 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
sql =
"select emp.empno\n"
- + "from sales.emp as e(\n"
- + " mpno,name,ob,gr,iredate,al,omm,eptno,lacker)\n"
- + "where e.mpno=1 order by ^";
+ + "from sales.emp as e(\n"
+ + " mpno,name,ob,gr,iredate,al,omm,eptno,lacker)\n"
+ + "where e.mpno=1 order by ^";
assertComplete(
sql,
EXPR_KEYWORDS,
@@ -801,10 +813,10 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
// with A).
sql =
"select * from sales.emp a where deptno in ("
- + "select * from sales.dept b where ^)";
+ + "select * from sales.dept b where ^)";
String simplifiedSql =
"SELECT * FROM sales.emp a WHERE deptno in ("
- + " SELECT * FROM sales.dept b WHERE _suggest_ )";
+ + " SELECT * FROM sales.dept b WHERE _suggest_ )";
assertSimplify(sql, simplifiedSql);
assertComplete(
sql,
@@ -816,68 +828,68 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
@Test public void testSimpleParserTokenizer() {
String sql =
"select"
- + " 12"
- + " "
- + "*"
- + " 1.23e45"
- + " "
- + "("
- + "\"an id\""
- + ","
- + " "
- + "\"an id with \"\"quotes' inside\""
- + ","
- + " "
- + "/* a comment, with 'quotes', over\nmultiple lines\nand select keyword */"
- + "\n "
- + "("
- + " "
- + "a"
- + " "
- + "different"
- + " "
- + "// comment\n\r"
- + "//and a comment /* containing comment */ and then some more\r"
- + ")"
- + " "
- + "from"
- + " "
- + "t"
- + ")"
- + ")"
- + "/* a comment after close paren */"
- + " "
- + "("
- + "'quoted'"
- + " "
- + "'string with ''single and \"double\"\" quote'"
- + ")";
+ + " 12"
+ + " "
+ + "*"
+ + " 1.23e45"
+ + " "
+ + "("
+ + "\"an id\""
+ + ","
+ + " "
+ + "\"an id with \"\"quotes' inside\""
+ + ","
+ + " "
+ + "/* a comment, with 'quotes', over\nmultiple lines\nand select keyword */"
+ + "\n "
+ + "("
+ + " "
+ + "a"
+ + " "
+ + "different"
+ + " "
+ + "// comment\n\r"
+ + "//and a comment /* containing comment */ and then some more\r"
+ + ")"
+ + " "
+ + "from"
+ + " "
+ + "t"
+ + ")"
+ + ")"
+ + "/* a comment after close paren */"
+ + " "
+ + "("
+ + "'quoted'"
+ + " "
+ + "'string with ''single and \"double\"\" quote'"
+ + ")";
String expected =
"SELECT\n"
- + "ID(12)\n"
- + "ID(*)\n"
- + "ID(1.23e45)\n"
- + "LPAREN\n"
- + "DQID(\"an id\")\n"
- + "COMMA\n"
- + "DQID(\"an id with \"\"quotes' inside\")\n"
- + "COMMA\n"
- + "COMMENT\n"
- + "LPAREN\n"
- + "ID(a)\n"
- + "ID(different)\n"
- + "COMMENT\n"
- + "COMMENT\n"
- + "RPAREN\n"
- + "FROM\n"
- + "ID(t)\n"
- + "RPAREN\n"
- + "RPAREN\n"
- + "COMMENT\n"
- + "LPAREN\n"
- + "SQID('quoted')\n"
- + "SQID('string with ''single and \"double\"\" quote')\n"
- + "RPAREN\n";
+ + "ID(12)\n"
+ + "ID(*)\n"
+ + "ID(1.23e45)\n"
+ + "LPAREN\n"
+ + "DQID(\"an id\")\n"
+ + "COMMA\n"
+ + "DQID(\"an id with \"\"quotes' inside\")\n"
+ + "COMMA\n"
+ + "COMMENT\n"
+ + "LPAREN\n"
+ + "ID(a)\n"
+ + "ID(different)\n"
+ + "COMMENT\n"
+ + "COMMENT\n"
+ + "RPAREN\n"
+ + "FROM\n"
+ + "ID(t)\n"
+ + "RPAREN\n"
+ + "RPAREN\n"
+ + "COMMENT\n"
+ + "LPAREN\n"
+ + "SQID('quoted')\n"
+ + "SQID('string with ''single and \"double\"\" quote')\n"
+ + "RPAREN\n";
assertTokenizesTo(sql, expected);
// Tokenizer should be lenient if input ends mid-token
@@ -947,16 +959,16 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
// on
sql =
"select a.empno, b.deptno from sales.emp a join sales.dept b "
- + "on a.deptno=^";
+ + "on a.deptno=^";
expected =
"SELECT * FROM sales.emp a JOIN sales.dept b "
- + "ON a.deptno= _suggest_";
+ + "ON a.deptno= _suggest_";
assertSimplify(sql, expected);
// where
sql =
"select a.empno, b.deptno from sales.emp a, sales.dept b "
- + "where ^";
+ + "where ^";
expected = "SELECT * FROM sales.emp a , sales.dept b WHERE _suggest_";
assertSimplify(sql, expected);
@@ -968,27 +980,27 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
// subquery in from
sql =
"select t.^ from (select 1 as x, 2 as y from sales.emp) as t "
- + "where t.dummy=1";
+ + "where t.dummy=1";
expected =
"SELECT t. _suggest_ "
- + "FROM ( SELECT 0 AS x , 0 AS y FROM sales.emp ) as t";
+ + "FROM ( SELECT 0 AS x , 0 AS y FROM sales.emp ) as t";
assertSimplify(sql, expected);
sql =
"select t. from (select 1 as x, 2 as y from "
- + "(select x from sales.emp)) as t where ^";
+ + "(select x from sales.emp)) as t where ^";
expected =
"SELECT * FROM ( SELECT 0 AS x , 0 AS y FROM "
- + "( SELECT 0 AS x FROM sales.emp ) ) as t WHERE _suggest_";
+ + "( SELECT 0 AS x FROM sales.emp ) ) as t WHERE _suggest_";
assertSimplify(sql, expected);
sql =
"select ^from (select 1 as x, 2 as y from sales.emp), "
- + "(select 2 as y from (select m from n where)) as t "
- + "where t.dummy=1";
+ + "(select 2 as y from (select m from n where)) as t "
+ + "where t.dummy=1";
expected =
"SELECT _suggest_ FROM ( SELECT 0 AS x , 0 AS y FROM sales.emp ) "
- + ", ( SELECT 0 AS y FROM ( SELECT 0 AS m FROM n ) ) as t";
+ + ", ( SELECT 0 AS y FROM ( SELECT 0 AS m FROM n ) ) as t";
assertSimplify(sql, expected);
// Note: completes the missing close paren; wipes out select clause of
@@ -1009,11 +1021,11 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
// 4. removes SELECT clause of outer query.
sql =
"select x + y + 32 from "
- + "(select 1 as x, 2 as y from sales group by invalid stuff) as t "
- + "where x in (select deptno from emp where foo + t.^ < 10)";
+ + "(select 1 as x, 2 as y from sales group by invalid stuff) as t "
+ + "where x in (select deptno from emp where foo + t.^ < 10)";
expected =
"SELECT * FROM ( SELECT 0 AS x , 0 AS y FROM sales ) as t "
- + "WHERE x in ( SELECT * FROM emp WHERE foo + t. _suggest_ < 10 )";
+ + "WHERE x in ( SELECT * FROM emp WHERE foo + t. _suggest_ < 10 )";
assertSimplify(sql, expected);
// if hint is in FROM, can remove other members of FROM clause
@@ -1028,26 +1040,26 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
sql =
"select count(1) from sales.emp a "
- + "where substring(a.^ FROM 3 for 6) = '1234'";
+ + "where substring(a.^ FROM 3 for 6) = '1234'";
expected =
"SELECT * FROM sales.emp a "
- + "WHERE substring ( a. _suggest_ FROM 3 for 6 ) = '1234'";
+ + "WHERE substring ( a. _suggest_ FROM 3 for 6 ) = '1234'";
assertSimplify(sql, expected);
// missing ')' following subquery
sql =
"select * from sales.emp a where deptno in ("
- + "select * from sales.dept b where ^";
+ + "select * from sales.dept b where ^";
expected =
"SELECT * FROM sales.emp a WHERE deptno in ("
- + " SELECT * FROM sales.dept b WHERE _suggest_ )";
+ + " SELECT * FROM sales.dept b WHERE _suggest_ )";
assertSimplify(sql, expected);
// keyword embedded in single and double quoted string should be
// ignored
sql =
"select 'a cat from a king' as foobar, 1 / 2 \"where\" from t "
- + "group by t.^ order by 123";
+ + "group by t.^ order by 123";
expected = "SELECT * FROM t GROUP BY t. _suggest_";
assertSimplify(sql, expected);
@@ -1088,12 +1100,12 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
String sql = "select * from emp where e^ and emp.deptno = 10";
final String expected =
"COLUMN(EMPNO)\n"
- + "COLUMN(ENAME)\n"
- + "KEYWORD(ELEMENT)\n"
- + "KEYWORD(EXISTS)\n"
- + "KEYWORD(EXP)\n"
- + "KEYWORD(EXTRACT)\n"
- + "TABLE(EMP)\n";
+ + "COLUMN(ENAME)\n"
+ + "KEYWORD(ELEMENT)\n"
+ + "KEYWORD(EXISTS)\n"
+ + "KEYWORD(EXP)\n"
+ + "KEYWORD(EXTRACT)\n"
+ + "TABLE(EMP)\n";
assertComplete(sql, expected, "e");
// cursor in middle of word and at end
@@ -1174,13 +1186,13 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
assertSimplify(sql, simplified);
}
+ /** Factory that creates testers. */
private static class AdvisorTesterFactory extends DelegatingSqlTestFactory {
public AdvisorTesterFactory() {
super(DefaultSqlTestFactory.INSTANCE);
}
- @Override
- public SqlValidator getValidator(SqlTestFactory factory) {
+ @Override public SqlValidator getValidator(SqlTestFactory factory) {
final RelDataTypeFactory typeFactory =
new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
final SqlConformance conformance = (SqlConformance) get("conformance");
@@ -1192,8 +1204,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
conformance);
}
- @Override
- public SqlAdvisor createAdvisor(SqlValidatorWithHints validator) {
+ @Override public SqlAdvisor createAdvisor(SqlValidatorWithHints validator) {
return new SqlAdvisor(validator);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
index c1ce991..8987b75 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
@@ -14,33 +14,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
-
-import java.math.*;
-
-import java.sql.*;
-import java.text.*;
-
-import java.util.*;
-import java.util.regex.*;
-
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.fun.*;
-import org.eigenbase.sql.parser.*;
-import org.eigenbase.sql.type.*;
-import org.eigenbase.sql.util.SqlString;
-import org.eigenbase.test.*;
-import org.eigenbase.util.*;
-
-import net.hydromatic.optiq.runtime.Hook;
-import net.hydromatic.optiq.test.OptiqAssert;
+package org.apache.calcite.sql.test;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlJdbcFunctionCall;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.BasicSqlType;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.util.SqlString;
+import org.apache.calcite.test.CalciteAssert;
+import org.apache.calcite.test.SqlLimitsTest;
+import org.apache.calcite.util.Bug;
+import org.apache.calcite.util.Holder;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
import com.google.common.base.Function;
-import org.junit.*;
-
-import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.List;
+import java.util.TimeZone;
+import java.util.regex.Pattern;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Contains unit tests for all operators. Each of the methods is named after an
@@ -63,7 +75,7 @@ import static org.junit.Assert.*;
*
* <p>A typical method will be named after the operator it is testing (say
* <code>testSubstringFunc</code>). It first calls
- * {@link SqlTester#setFor(org.eigenbase.sql.SqlOperator, org.eigenbase.sql.test.SqlTester.VmName...)}
+ * {@link SqlTester#setFor(org.apache.calcite.sql.SqlOperator, org.apache.calcite.sql.test.SqlTester.VmName...)}
* to declare which operator it is testing.
*
* <blockquote>
@@ -142,7 +154,7 @@ public abstract class SqlOperatorBaseTest {
public static final Pattern TIMESTAMP_PATTERN =
Pattern.compile(
"[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] "
- + "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]");
+ + "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]");
/**
* Regular expression for a SQL DATE value.
@@ -1315,7 +1327,7 @@ public abstract class SqlOperatorBaseTest {
"CHAR(3)");
tester.checkString(
"case 1 when 1 then cast('a' as varchar(1)) "
- + "when 2 then cast('bcd' as varchar(3)) end",
+ + "when 2 then cast('bcd' as varchar(3)) end",
"a",
"VARCHAR(3)");
if (DECIMAL) {
@@ -1389,29 +1401,29 @@ public abstract class SqlOperatorBaseTest {
// multiple values in some cases (introduced in SQL:2011)
tester.checkString(
"case 1 "
- + "when 1, 2 then '1 or 2' "
- + "when 2 then 'not possible' "
- + "when 3, 2 then '3' "
- + "else 'none of the above' "
- + "end",
+ + "when 1, 2 then '1 or 2' "
+ + "when 2 then 'not possible' "
+ + "when 3, 2 then '3' "
+ + "else 'none of the above' "
+ + "end",
"1 or 2 ",
"CHAR(17) NOT NULL");
tester.checkString(
"case 2 "
- + "when 1, 2 then '1 or 2' "
- + "when 2 then 'not possible' "
- + "when 3, 2 then '3' "
- + "else 'none of the above' "
- + "end",
+ + "when 1, 2 then '1 or 2' "
+ + "when 2 then 'not possible' "
+ + "when 3, 2 then '3' "
+ + "else 'none of the above' "
+ + "end",
"1 or 2 ",
"CHAR(17) NOT NULL");
tester.checkString(
"case 3 "
- + "when 1, 2 then '1 or 2' "
- + "when 2 then 'not possible' "
- + "when 3, 2 then '3' "
- + "else 'none of the above' "
- + "end",
+ + "when 1, 2 then '1 or 2' "
+ + "when 2 then 'not possible' "
+ + "when 3, 2 then '3' "
+ + "else 'none of the above' "
+ + "end",
"3 ",
"CHAR(17) NOT NULL");
tester.checkString(
@@ -1714,26 +1726,26 @@ public abstract class SqlOperatorBaseTest {
"RecordType(INTEGER NOT NULL EXPR$0, INTEGER EXPR$1) NOT NULL");
tester.checkType(
"SELECT *,(SELECT * FROM (VALUES(CAST(10 as BIGINT)))) "
- + "FROM (VALUES(CAST(10 as bigint)))",
+ + "FROM (VALUES(CAST(10 as bigint)))",
"RecordType(BIGINT NOT NULL EXPR$0, BIGINT EXPR$1) NOT NULL");
tester.checkType(
" SELECT *,(SELECT * FROM (VALUES(10.5))) FROM (VALUES(10.5))",
"RecordType(DECIMAL(3, 1) NOT NULL EXPR$0, DECIMAL(3, 1) EXPR$1) NOT NULL");
tester.checkType(
"SELECT *,(SELECT * FROM (VALUES('this is a char'))) "
- + "FROM (VALUES('this is a char too'))",
+ + "FROM (VALUES('this is a char too'))",
"RecordType(CHAR(18) NOT NULL EXPR$0, CHAR(14) EXPR$1) NOT NULL");
tester.checkType(
"SELECT *,(SELECT * FROM (VALUES(true))) FROM (values(false))",
"RecordType(BOOLEAN NOT NULL EXPR$0, BOOLEAN EXPR$1) NOT NULL");
tester.checkType(
" SELECT *,(SELECT * FROM (VALUES(cast('abcd' as varchar(10))))) "
- + "FROM (VALUES(CAST('abcd' as varchar(10))))",
+ + "FROM (VALUES(CAST('abcd' as varchar(10))))",
"RecordType(VARCHAR(10) NOT NULL EXPR$0, VARCHAR(10) EXPR$1) NOT NULL");
tester.checkType(
"SELECT *,"
- + " (SELECT * FROM (VALUES(TIMESTAMP '2006-01-01 12:00:05'))) "
- + "FROM (VALUES(TIMESTAMP '2006-01-01 12:00:05'))",
+ + " (SELECT * FROM (VALUES(TIMESTAMP '2006-01-01 12:00:05'))) "
+ + "FROM (VALUES(TIMESTAMP '2006-01-01 12:00:05'))",
"RecordType(TIMESTAMP(0) NOT NULL EXPR$0, TIMESTAMP(0) EXPR$1) NOT NULL");
}
}
@@ -2487,30 +2499,30 @@ public abstract class SqlOperatorBaseTest {
// combine '<datetime> + <interval>' with '<datetime> - <datetime>'
tester.checkScalar(
"timestamp '1969-04-29 0:0:0' +"
- + " (timestamp '2008-07-15 15:28:00' - "
- + " timestamp '1969-04-29 0:0:0') day to second / 2",
+ + " (timestamp '2008-07-15 15:28:00' - "
+ + " timestamp '1969-04-29 0:0:0') day to second / 2",
"1988-12-06 07:44:00",
"TIMESTAMP(0) NOT NULL");
tester.checkScalar(
"date '1969-04-29' +"
- + " (date '2008-07-15' - "
- + " date '1969-04-29') day / 2",
+ + " (date '2008-07-15' - "
+ + " date '1969-04-29') day / 2",
"1988-12-06",
"DATE NOT NULL");
tester.checkScalar(
"time '01:23:44' +"
- + " (time '15:28:00' - "
- + " time '01:23:44') hour to second / 2",
+ + " (time '15:28:00' - "
+ + " time '01:23:44') hour to second / 2",
"08:25:52",
"TIME(0) NOT NULL");
if (Bug.DT1684_FIXED) {
tester.checkBoolean(
"(date '1969-04-29' +"
- + " (CURRENT_DATE - "
- + " date '1969-04-29') day / 2) is not null",
+ + " (CURRENT_DATE - "
+ + " date '1969-04-29') day / 2) is not null",
Boolean.TRUE);
}
// TODO: Add tests for year month intervals (currently not supported)
@@ -3195,15 +3207,15 @@ public abstract class SqlOperatorBaseTest {
tester.checkFails(
"'yd' similar to '[x-ze-a]d'",
"Illegal character range near index 6\n"
- + "\\[x-ze-a\\]d\n"
- + " \\^",
+ + "\\[x-ze-a\\]d\n"
+ + " \\^",
true); // illegal range
tester.checkFails(
"'yd3223' similar to '[:LOWER:]{2}[:DIGIT:]{,5}'",
"Illegal repetition near index 20\n"
- + "\\[\\:LOWER\\:\\]\\{2\\}\\[\\:DIGIT\\:\\]\\{,5\\}\n"
- + " \\^",
+ + "\\[\\:LOWER\\:\\]\\{2\\}\\[\\:DIGIT\\:\\]\\{,5\\}\n"
+ + " \\^",
true);
tester.checkFails(
@@ -3273,7 +3285,7 @@ public abstract class SqlOperatorBaseTest {
tester.checkBoolean(
"'YD 3223' similar to "
- + "'[:UPPER:]{2}||[:WHITESPACE:]*[:DIGIT:]{4}'",
+ + "'[:UPPER:]{2}||[:WHITESPACE:]*[:DIGIT:]{4}'",
Boolean.TRUE);
tester.checkBoolean(
@@ -3282,12 +3294,12 @@ public abstract class SqlOperatorBaseTest {
tester.checkBoolean(
"'YD\t3223' similar to "
- + "'[:UPPER:]{2}[:WHITESPACE:]*[:DIGIT:]{4}'",
+ + "'[:UPPER:]{2}[:WHITESPACE:]*[:DIGIT:]{4}'",
Boolean.TRUE);
tester.checkBoolean(
"'YD\t\t3223' similar to "
- + "'([:UPPER:]{2}[:WHITESPACE:]+)||[:DIGIT:]{4}'",
+ + "'([:UPPER:]{2}[:WHITESPACE:]+)||[:DIGIT:]{4}'",
Boolean.TRUE);
}
}
@@ -3323,14 +3335,14 @@ public abstract class SqlOperatorBaseTest {
if (enable) {
tester.checkString(
"overlay(cast('ABCdef' as varchar(10)) placing "
- + "cast('abc' as char(5)) from 1 for 2)",
+ + "cast('abc' as char(5)) from 1 for 2)",
"abc Cdef",
"VARCHAR(15) NOT NULL");
}
if (enable) {
tester.checkString(
"overlay(cast('ABCdef' as char(10)) placing "
- + "cast('abc' as char(5)) from 1 for 2)",
+ + "cast('abc' as char(5)) from 1 for 2)",
"abc Cdef ",
"VARCHAR(15) NOT NULL");
}
@@ -3350,14 +3362,14 @@ public abstract class SqlOperatorBaseTest {
if (enable) {
tester.checkString(
"overlay(cast(x'ABCdef' as varbinary(5)) placing "
- + "cast(x'abcd' as binary(3)) from 1 for 2)",
+ + "cast(x'abcd' as binary(3)) from 1 for 2)",
"abc Cdef",
"VARBINARY(8) NOT NULL");
}
if (enable) {
tester.checkString(
"overlay(cast(x'ABCdef' as binary(5)) placing "
- + "cast(x'abcd' as binary(3)) from 1 for 2)",
+ + "cast(x'abcd' as binary(3)) from 1 for 2)",
"abc Cdef ",
"VARBINARY(8) NOT NULL");
}
@@ -3872,7 +3884,7 @@ public abstract class SqlOperatorBaseTest {
protected static Pair<String, Hook.Closeable> currentTimeString(TimeZone tz) {
final Calendar calendar;
final Hook.Closeable closeable;
- if (OptiqAssert.ENABLE_SLOW) {
+ if (CalciteAssert.ENABLE_SLOW) {
calendar = getCalendarNotTooNear(Calendar.HOUR_OF_DAY);
closeable = new Hook.Closeable() {
public void close() {}
@@ -3980,16 +3992,16 @@ public abstract class SqlOperatorBaseTest {
tester.checkFails(
"trim('xy' from 'abcde')",
"could not calculate results for the following row:\n"
- + "\\[ 0 \\]\n"
- + "Messages:\n"
- + "\\[0\\]:PC=0 Code=22027 ",
+ + "\\[ 0 \\]\n"
+ + "Messages:\n"
+ + "\\[0\\]:PC=0 Code=22027 ",
true);
tester.checkFails(
"trim('' from 'abcde')",
"could not calculate results for the following row:\n"
- + "\\[ 0 \\]\n"
- + "Messages:\n"
- + "\\[0\\]:PC=0 Code=22027 ",
+ + "\\[ 0 \\]\n"
+ + "Messages:\n"
+ + "\\[0\\]:PC=0 Code=22027 ",
true);
}
}
@@ -4182,7 +4194,7 @@ public abstract class SqlOperatorBaseTest {
tester.checkFails(
"^ARRAY ['foo', 'bar']['baz']^",
"Cannot apply 'ITEM' to arguments of type 'ITEM\\(<CHAR\\(3\\) ARRAY>, <CHAR\\(3\\)>\\)'\\. Supported form\\(s\\): <ARRAY>\\[<INTEGER>\\]\n"
- + "<MAP>\\[<VALUE>\\]",
+ + "<MAP>\\[<VALUE>\\]",
false);
// Array of INTEGER NOT NULL is interesting because we might be tempted
@@ -4934,7 +4946,7 @@ public abstract class SqlOperatorBaseTest {
literal.toSqlString(SqlDialect.DUMMY);
final String expr =
"CAST(" + literalString
- + " AS " + type + ")";
+ + " AS " + type + ")";
try {
tester.checkType(
expr,
@@ -5136,7 +5148,7 @@ public abstract class SqlOperatorBaseTest {
}
/**
- * Creates a {@link org.eigenbase.sql.test.SqlTester} based on a JDBC
+ * Creates a {@link org.apache.calcite.sql.test.SqlTester} based on a JDBC
* connection.
*/
public static SqlTester tester(Connection connection) {
@@ -5144,7 +5156,7 @@ public abstract class SqlOperatorBaseTest {
}
/**
- * Implementation of {@link org.eigenbase.sql.test.SqlTester} based on a
+ * Implementation of {@link org.apache.calcite.sql.test.SqlTester} based on a
* JDBC connection.
*/
protected static class TesterImpl extends SqlTesterImpl {
@@ -5155,8 +5167,7 @@ public abstract class SqlOperatorBaseTest {
this.connection = connection;
}
- @Override
- public void check(
+ @Override public void check(
String query,
TypeChecker typeChecker,
ResultChecker resultChecker) {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorTest.java
index 70c4544..91bc0f8 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorTest.java
@@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
+package org.apache.calcite.sql.test;
-import org.eigenbase.sql.validate.*;
-import org.eigenbase.test.*;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.test.SqlValidatorTestCase;
/**
* Concrete subclass of {@link SqlOperatorBaseTest} which checks against
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
index 5963ceb..26df28d 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
@@ -14,18 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
+package org.apache.calcite.sql.test;
-import java.io.*;
-
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.parser.*;
-import org.eigenbase.sql.pretty.*;
-import org.eigenbase.test.*;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.pretty.SqlPrettyWriter;
+import org.apache.calcite.test.DiffRepository;
import org.junit.Test;
-import static org.junit.Assert.*;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import static org.junit.Assert.assertTrue;
/**
* Unit test for {@link SqlPrettyWriter}.
@@ -58,8 +63,7 @@ public class SqlPrettyWriterTest {
try {
node = SqlParser.create(sql).parseQuery();
} catch (SqlParseException e) {
- String message =
- "Received error while parsing SQL '" + sql
+ String message = "Received error while parsing SQL '" + sql
+ "'; error is:" + NL + e.toString();
throw new AssertionError(message);
}
@@ -117,8 +121,7 @@ public class SqlPrettyWriterTest {
String expectedDesc,
String expected) throws Exception {
final SqlNode node =
- parseQuery(
- "select x as a, b as b, c as c, d,"
+ parseQuery("select x as a, b as b, c as c, d,"
+ " 'mixed-Case string',"
+ " unquotedCamelCaseId,"
+ " \"quoted id\" "
@@ -223,16 +226,16 @@ public class SqlPrettyWriterTest {
true,
"case 1 when 2 + 3 then 4 when case a when b then c else d end then 6 else 7 end",
"CASE" + NL
- + "WHEN 1 = 2 + 3" + NL
- + "THEN 4" + NL
- + "WHEN 1 = CASE" + NL
- + " WHEN `A` = `B`" + NL // todo: indent should be 4 not 8
- + " THEN `C`" + NL
- + " ELSE `D`" + NL
- + " END" + NL
- + "THEN 6" + NL
- + "ELSE 7" + NL
- + "END");
+ + "WHEN 1 = 2 + 3" + NL
+ + "THEN 4" + NL
+ + "WHEN 1 = CASE" + NL
+ + " WHEN `A` = `B`" + NL // todo: indent should be 4 not 8
+ + " THEN `C`" + NL
+ + " ELSE `D`" + NL
+ + " END" + NL
+ + "THEN 6" + NL
+ + "ELSE 7" + NL
+ + "END");
}
@Test public void testCase2() {
@@ -262,7 +265,7 @@ public class SqlPrettyWriterTest {
assertExprPrintsTo(
true,
"'x' /* comment */ 'y'" + NL
- + " 'z' ",
+ + " 'z' ",
"'x'" + NL + "'y'" + NL + "'z'");
}
@@ -277,11 +280,11 @@ public class SqlPrettyWriterTest {
assertPrintsTo(
true,
"select * from t "
- + "union select * from ("
- + " select * from u "
- + " union select * from v) "
- + "union select * from w "
- + "order by a, b",
+ + "union select * from ("
+ + " select * from u "
+ + " union select * from v) "
+ + "union select * from w "
+ + "order by a, b",
// todo: SELECT should not be indended from UNION, like this:
// UNION
@@ -308,19 +311,19 @@ public class SqlPrettyWriterTest {
@Test public void testWhereListItemsOnSeparateLinesOr() throws Exception {
checkPrettySeparateLines(
"select x"
- + " from y"
- + " where h is not null and i < j"
- + " or ((a or b) is true) and d not in (f,g)"
- + " or x <> z");
+ + " from y"
+ + " where h is not null and i < j"
+ + " or ((a or b) is true) and d not in (f,g)"
+ + " or x <> z");
}
@Test public void testWhereListItemsOnSeparateLinesAnd() throws Exception {
checkPrettySeparateLines(
"select x"
- + " from y"
- + " where h is not null and (i < j"
- + " or ((a or b) is true)) and (d not in (f,g)"
- + " or v <> ((w * x) + y) * z)");
+ + " from y"
+ + " where h is not null and (i < j"
+ + " or ((a or b) is true)) and (d not in (f,g)"
+ + " or v <> ((w * x) + y) * z)");
}
private void checkPrettySeparateLines(String sql) {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlTestFactory.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlTestFactory.java b/core/src/test/java/org/apache/calcite/sql/test/SqlTestFactory.java
index 9c5e2a2..7aadf37 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlTestFactory.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlTestFactory.java
@@ -14,18 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
+package org.apache.calcite.sql.test;
-import org.eigenbase.sql.SqlOperatorTable;
-import org.eigenbase.sql.advise.SqlAdvisor;
-import org.eigenbase.sql.parser.SqlParser;
-import org.eigenbase.sql.validate.SqlValidator;
-import org.eigenbase.sql.validate.SqlValidatorWithHints;
+import org.apache.calcite.sql.SqlOperatorTable;
+import org.apache.calcite.sql.advise.SqlAdvisor;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorWithHints;
/**
* Creates the objects needed to run a SQL parsing or validation test.
*
- * @see org.eigenbase.sql.test.SqlTester
+ * @see org.apache.calcite.sql.test.SqlTester
*/
public interface SqlTestFactory {
SqlOperatorTable createOperatorTable();
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java b/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java
index a6f27f9..a6790ab 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlTester.java
@@ -14,21 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
+package org.apache.calcite.sql.test;
+
+import org.apache.calcite.avatica.Casing;
+import org.apache.calcite.avatica.Quoting;
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.test.SqlValidatorTestCase;
import java.io.Closeable;
import java.sql.ResultSet;
-import org.eigenbase.reltype.*;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.validate.SqlConformance;
-import org.eigenbase.test.SqlValidatorTestCase;
-
-import net.hydromatic.avatica.Casing;
-import net.hydromatic.avatica.Quoting;
-
-import net.hydromatic.optiq.config.Lex;
-
/**
* SqlTester defines a callback for testing SQL queries and expressions.
*
@@ -363,10 +361,12 @@ public interface SqlTester extends Closeable, SqlValidatorTestCase.Tester {
//~ Inner Interfaces -------------------------------------------------------
+ /** Type checker. */
interface TypeChecker {
void checkType(RelDataType type);
}
+ /** Result checker. */
interface ResultChecker {
void checkResult(ResultSet result) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java b/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java
index c0c5a54..874655b 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java
@@ -14,38 +14,58 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
-
-import java.nio.charset.Charset;
-import java.util.*;
-
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.reltype.RelDataTypeField;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
-import org.eigenbase.sql.parser.*;
-import org.eigenbase.sql.type.SqlTypeName;
-import org.eigenbase.sql.util.SqlShuttle;
-import org.eigenbase.sql.validate.*;
-import org.eigenbase.test.SqlValidatorTestCase;
-import org.eigenbase.util.*;
-
-import net.hydromatic.avatica.Casing;
-import net.hydromatic.avatica.Quoting;
-
-import net.hydromatic.optiq.config.Lex;
-import net.hydromatic.optiq.runtime.Utilities;
+package org.apache.calcite.sql.test;
+
+import org.apache.calcite.avatica.Casing;
+import org.apache.calcite.avatica.Quoting;
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.runtime.Utilities;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlCollation;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlIntervalLiteral;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.parser.SqlParserUtil;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.util.SqlShuttle;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlMonotonicity;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorScope;
+import org.apache.calcite.test.SqlValidatorTestCase;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.TestUtil;
+import org.apache.calcite.util.Util;
import com.google.common.collect.ImmutableList;
-import static org.eigenbase.sql.SqlUtil.stripAs;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import static org.apache.calcite.sql.SqlUtil.stripAs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
/**
- * Implementation of {@link org.eigenbase.test.SqlValidatorTestCase.Tester}
+ * Implementation of {@link org.apache.calcite.test.SqlValidatorTestCase.Tester}
* that talks to a mock catalog.
*/
public class SqlTesterImpl implements SqlTester {
@@ -97,8 +117,8 @@ public class SqlTesterImpl implements SqlTester {
e.printStackTrace();
throw new AssertionError(
"Error did not match expected ["
- + expectedMsgPattern + "] while parsing query ["
- + sap.sql + "]");
+ + expectedMsgPattern + "] while parsing query ["
+ + sap.sql + "]");
}
return;
} catch (Throwable e) {
@@ -283,8 +303,7 @@ public class SqlTesterImpl implements SqlTester {
private SqlTesterImpl with(final String name2, final Object value) {
return new SqlTesterImpl(
new DelegatingSqlTestFactory(factory) {
- @Override
- public Object get(String name) {
+ @Override public Object get(String name) {
if (name.equals(name2)) {
return value;
}
@@ -521,8 +540,7 @@ public class SqlTesterImpl implements SqlTester {
SqlStdOperatorTable.CURRENT_TIME,
SqlStdOperatorTable.CURRENT_TIMESTAMP);
- @Override
- public SqlNode visit(SqlLiteral literal) {
+ @Override public SqlNode visit(SqlLiteral literal) {
if (!isNull(literal)
&& literal.getTypeName() != SqlTypeName.SYMBOL) {
literalSet.add(literal);
@@ -530,8 +548,7 @@ public class SqlTesterImpl implements SqlTester {
return literal;
}
- @Override
- public SqlNode visit(SqlCall call) {
+ @Override public SqlNode visit(SqlCall call) {
final SqlOperator operator = call.getOperator();
if (operator == SqlStdOperatorTable.CAST
&& isNull(call.operand(0))) {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlTests.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlTests.java b/core/src/test/java/org/apache/calcite/sql/test/SqlTests.java
index 47a371a..9fb82b3 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlTests.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlTests.java
@@ -14,22 +14,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
+package org.apache.calcite.sql.test;
+
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.type.SqlTypeName;
import java.sql.ResultSet;
import java.sql.Types;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.regex.Pattern;
-import org.eigenbase.reltype.*;
-import org.eigenbase.sql.type.*;
-
-import net.hydromatic.avatica.ColumnMetaData;
-
-import static org.eigenbase.sql.test.SqlTester.*;
+import static org.apache.calcite.sql.test.SqlTester.ResultChecker;
+import static org.apache.calcite.sql.test.SqlTester.TypeChecker;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Utility methods.
@@ -213,13 +220,11 @@ public abstract class SqlTests {
fail("Query returned 2 or more rows, expected 1");
}
if (!pattern.matcher(actual).matches()) {
- fail(
- "Query returned '"
+ fail("Query returned '"
+ actual
+ "', expected '"
+ pattern.pattern()
- + "'"
- );
+ + "'");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java
index cce7df7..b8f6243 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlTypeNameTest.java
@@ -14,15 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.sql.test;
+package org.apache.calcite.sql.test;
-import java.sql.Types;
-
-import org.eigenbase.sql.type.*;
+import org.apache.calcite.sql.type.ExtraSqlTypes;
+import org.apache.calcite.sql.type.SqlTypeName;
import org.junit.Test;
-import static org.junit.Assert.*;
+import java.sql.Types;
+
+import static org.junit.Assert.assertEquals;
/**
* Tests types supported by {@link SqlTypeName}.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/sql/test/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/package-info.java b/core/src/test/java/org/apache/calcite/sql/test/package-info.java
index 9a77bf1..9d3e4ec 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/package-info.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/package-info.java
@@ -18,6 +18,6 @@
/**
* Regression tests for the SQL model.
*/
-package org.eigenbase.sql.test;
+package org.apache.calcite.sql.test;
// End package-info.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
index 54a306d..82931d0 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
@@ -14,50 +14,76 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.config.OptiqConnectionProperty;
-import net.hydromatic.optiq.impl.AbstractSchema;
-import net.hydromatic.optiq.impl.ViewTable;
-import net.hydromatic.optiq.impl.clone.CloneSchema;
-import net.hydromatic.optiq.impl.java.ReflectiveSchema;
-import net.hydromatic.optiq.impl.jdbc.JdbcSchema;
-import net.hydromatic.optiq.jdbc.MetaImpl;
-import net.hydromatic.optiq.jdbc.OptiqConnection;
-import net.hydromatic.optiq.jdbc.OptiqSchema;
-import net.hydromatic.optiq.materialize.Lattice;
-import net.hydromatic.optiq.runtime.Hook;
-
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.RelOptUtil;
-import org.eigenbase.util.*;
-
-import com.google.common.base.*;
+package org.apache.calcite.test;
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.clone.CloneSchema;
+import org.apache.calcite.adapter.java.ReflectiveSchema;
+import org.apache.calcite.adapter.jdbc.JdbcSchema;
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.MetaImpl;
+import org.apache.calcite.materialize.Lattice;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.impl.AbstractSchema;
+import org.apache.calcite.schema.impl.ViewTable;
+import org.apache.calcite.util.JsonBuilder;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
+
import com.google.common.base.Function;
-import com.google.common.cache.*;
+import com.google.common.base.Functions;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultiset;
import com.google.common.collect.Lists;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.lang.reflect.*;
-import java.sql.*;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TimeZone;
+import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import javax.sql.DataSource;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Fluid DSL for testing Calcite connections and queries.
*/
-public class OptiqAssert {
- private OptiqAssert() {}
+public class CalciteAssert {
+ private CalciteAssert() {}
/** Which database to use for tests that require a JDBC data source. By
* default the test suite runs against the embedded hsqldb database.
@@ -94,33 +120,27 @@ public class OptiqAssert {
/** Implementation of {@link AssertThat} that does nothing. */
private static final AssertThat DISABLED =
new AssertThat((Config) null) {
- @Override
- public AssertThat with(Config config) {
+ @Override public AssertThat with(Config config) {
return this;
}
- @Override
- public AssertThat with(ConnectionFactory connectionFactory) {
+ @Override public AssertThat with(ConnectionFactory connectionFactory) {
return this;
}
- @Override
- public AssertThat with(Map<String, String> map) {
+ @Override public AssertThat with(Map<String, String> map) {
return this;
}
- @Override
- public AssertThat with(String name, Object schema) {
+ @Override public AssertThat with(String name, Object schema) {
return this;
}
- @Override
- public AssertThat withModel(String model) {
+ @Override public AssertThat withModel(String model) {
return this;
}
- @Override
- public AssertQuery query(String sql) {
+ @Override public AssertQuery query(String sql) {
return NopAssertQuery.of(sql);
}
@@ -129,29 +149,26 @@ public class OptiqAssert {
return this;
}
- @Override
- public <T> AssertThat doWithConnection(Function<OptiqConnection, T> fn)
+ @Override public <T> AssertThat doWithConnection(
+ Function<CalciteConnection, T> fn)
throws Exception {
return this;
}
- @Override
- public AssertThat withSchema(String schema) {
+ @Override public AssertThat withSchema(String schema) {
return this;
}
- @Override
- public AssertThat enable(boolean enabled) {
+ @Override public AssertThat enable(boolean enabled) {
return this;
}
- @Override
- public AssertThat pooled() {
+ @Override public AssertThat pooled() {
return this;
}
};
- /** Creates an instance of {@code OptiqAssert} with the regular
+ /** Creates an instance of {@code CalciteAssert} with the regular
* configuration. */
public static AssertThat that() {
return new AssertThat(Config.REGULAR);
@@ -192,7 +209,7 @@ public class OptiqAssert {
return new Function<ResultSet, Void>() {
public Void apply(ResultSet resultSet) {
try {
- final String resultString = OptiqAssert.toString(resultSet);
+ final String resultString = CalciteAssert.toString(resultSet);
assertEquals(expected, Util.toLinux(resultString));
return null;
} catch (SQLException e) {
@@ -226,7 +243,7 @@ public class OptiqAssert {
return new Function<ResultSet, Void>() {
public Void apply(ResultSet resultSet) {
try {
- final int count = OptiqAssert.countRows(resultSet);
+ final int count = CalciteAssert.countRows(resultSet);
assertEquals(expected, count);
return null;
} catch (SQLException e) {
@@ -250,7 +267,7 @@ public class OptiqAssert {
++executeCount;
try {
final Collection result =
- OptiqAssert.toStringList(resultSet,
+ CalciteAssert.toStringList(resultSet,
ordered ? new ArrayList<String>() : new TreeSet<String>());
if (executeCount == 1) {
expected = result;
@@ -286,7 +303,7 @@ public class OptiqAssert {
Collections.sort(expectedList);
final List<String> actualList = Lists.newArrayList();
- OptiqAssert.toStringList(resultSet, actualList);
+ CalciteAssert.toStringList(resultSet, actualList);
Collections.sort(actualList);
// Use assertArrayEquals since it implements fine-grained comparison.
@@ -304,7 +321,7 @@ public class OptiqAssert {
return new Function<ResultSet, Void>() {
public Void apply(ResultSet s) {
try {
- final String actual = Util.toLinux(OptiqAssert.toString(s));
+ final String actual = Util.toLinux(CalciteAssert.toString(s));
if (!actual.contains(expected)) {
assertEquals("contains", expected, actual);
}
@@ -321,7 +338,7 @@ public class OptiqAssert {
return new Function<ResultSet, Void>() {
public Void apply(ResultSet s) {
try {
- final String actual = Util.toLinux(OptiqAssert.toString(s));
+ final String actual = Util.toLinux(CalciteAssert.toString(s));
final String maskedActual =
actual.replaceAll(", id = [0-9]+", "");
if (!maskedActual.contains(expected)) {
@@ -375,14 +392,14 @@ public class OptiqAssert {
Function<Throwable, Void> exceptionChecker) throws Exception {
final String message =
"With materializationsEnabled=" + materializationsEnabled
- + ", limit=" + limit;
+ + ", limit=" + limit;
final List<Hook.Closeable> closeableList = Lists.newArrayList();
try {
- ((OptiqConnection) connection).getProperties().setProperty(
- OptiqConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(),
+ ((CalciteConnection) connection).getProperties().setProperty(
+ CalciteConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(),
Boolean.toString(materializationsEnabled));
- ((OptiqConnection) connection).getProperties().setProperty(
- OptiqConnectionProperty.CREATE_MATERIALIZATIONS.camelName(),
+ ((CalciteConnection) connection).getProperties().setProperty(
+ CalciteConnectionProperty.CREATE_MATERIALIZATIONS.camelName(),
Boolean.toString(materializationsEnabled));
for (Pair<Hook, Function> hook : hooks) {
closeableList.add(hook.left.addThread(hook.right));
@@ -453,11 +470,11 @@ public class OptiqAssert {
}
});
try {
- ((OptiqConnection) connection).getProperties().setProperty(
- OptiqConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(),
+ ((CalciteConnection) connection).getProperties().setProperty(
+ CalciteConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(),
Boolean.toString(materializationsEnabled));
- ((OptiqConnection) connection).getProperties().setProperty(
- OptiqConnectionProperty.CREATE_MATERIALIZATIONS.camelName(),
+ ((CalciteConnection) connection).getProperties().setProperty(
+ CalciteConnectionProperty.CREATE_MATERIALIZATIONS.camelName(),
Boolean.toString(materializationsEnabled));
PreparedStatement statement = connection.prepareStatement(sql);
statement.close();
@@ -587,21 +604,23 @@ public class OptiqAssert {
case JDBC_FOODMART_WITH_LATTICE:
foodmart = rootSchema.getSubSchema("foodmart");
if (foodmart == null) {
- foodmart = OptiqAssert.addSchema(rootSchema, SchemaSpec.JDBC_FOODMART);
+ foodmart =
+ CalciteAssert.addSchema(rootSchema, SchemaSpec.JDBC_FOODMART);
}
foodmart.add("lattice",
- Lattice.create(foodmart.unwrap(OptiqSchema.class),
+ Lattice.create(foodmart.unwrap(CalciteSchema.class),
"select 1 from \"foodmart\".\"sales_fact_1997\" as s\n"
- + "join \"foodmart\".\"time_by_day\" as t using (\"time_id\")\n"
- + "join \"foodmart\".\"customer\" as c using (\"customer_id\")\n"
- + "join \"foodmart\".\"product\" as p using (\"product_id\")\n"
- + "join \"foodmart\".\"product_class\" as pc on p.\"product_class_id\" = pc.\"product_class_id\"",
+ + "join \"foodmart\".\"time_by_day\" as t using (\"time_id\")\n"
+ + "join \"foodmart\".\"customer\" as c using (\"customer_id\")\n"
+ + "join \"foodmart\".\"product\" as p using (\"product_id\")\n"
+ + "join \"foodmart\".\"product_class\" as pc on p.\"product_class_id\" = pc.\"product_class_id\"",
true));
return foodmart;
case CLONE_FOODMART:
foodmart = rootSchema.getSubSchema("foodmart");
if (foodmart == null) {
- foodmart = OptiqAssert.addSchema(rootSchema, SchemaSpec.JDBC_FOODMART);
+ foodmart =
+ CalciteAssert.addSchema(rootSchema, SchemaSpec.JDBC_FOODMART);
}
return rootSchema.add("foodmart2", new CloneSchema(foodmart));
case HR:
@@ -615,34 +634,34 @@ public class OptiqAssert {
post.add("EMP",
ViewTable.viewMacro(post,
"select * from (values\n"
- + " ('Jane', 10, 'F'),\n"
- + " ('Bob', 10, 'M'),\n"
- + " ('Eric', 20, 'M'),\n"
- + " ('Susan', 30, 'F'),\n"
- + " ('Alice', 30, 'F'),\n"
- + " ('Adam', 50, 'M'),\n"
- + " ('Eve', 50, 'F'),\n"
- + " ('Grace', 60, 'F'),\n"
- + " ('Wilma', cast(null as integer), 'F'))\n"
- + " as t(ename, deptno, gender)",
+ + " ('Jane', 10, 'F'),\n"
+ + " ('Bob', 10, 'M'),\n"
+ + " ('Eric', 20, 'M'),\n"
+ + " ('Susan', 30, 'F'),\n"
+ + " ('Alice', 30, 'F'),\n"
+ + " ('Adam', 50, 'M'),\n"
+ + " ('Eve', 50, 'F'),\n"
+ + " ('Grace', 60, 'F'),\n"
+ + " ('Wilma', cast(null as integer), 'F'))\n"
+ + " as t(ename, deptno, gender)",
ImmutableList.<String>of()));
post.add("DEPT",
ViewTable.viewMacro(post,
"select * from (values\n"
- + " (10, 'Sales'),\n"
- + " (20, 'Marketing'),\n"
- + " (30, 'Engineering'),\n"
- + " (40, 'Empty')) as t(deptno, dname)",
+ + " (10, 'Sales'),\n"
+ + " (20, 'Marketing'),\n"
+ + " (30, 'Engineering'),\n"
+ + " (40, 'Empty')) as t(deptno, dname)",
ImmutableList.<String>of()));
post.add("EMPS",
ViewTable.viewMacro(post,
"select * from (values\n"
- + " (100, 'Fred', 10, CAST(NULL AS CHAR(1)), CAST(NULL AS VARCHAR(20)), 40, 25, TRUE, FALSE, DATE '1996-08-03'),\n"
- + " (110, 'Eric', 20, 'M', 'San Francisco', 3, 80, UNKNOWN, FALSE, DATE '2001-01-01'),\n"
- + " (110, 'John', 40, 'M', 'Vancouver', 2, CAST(NULL AS INT), FALSE, TRUE, DATE '2002-05-03'),\n"
- + " (120, 'Wilma', 20, 'F', CAST(NULL AS VARCHAR(20)), 1, 5, UNKNOWN, TRUE, DATE '2005-09-07'),\n"
- + " (130, 'Alice', 40, 'F', 'Vancouver', 2, CAST(NULL AS INT), FALSE, TRUE, DATE '2007-01-01'))\n"
- + " as t(empno, name, deptno, gender, city, empid, age, slacker, manager, joinedat)",
+ + " (100, 'Fred', 10, CAST(NULL AS CHAR(1)), CAST(NULL AS VARCHAR(20)), 40, 25, TRUE, FALSE, DATE '1996-08-03'),\n"
+ + " (110, 'Eric', 20, 'M', 'San Francisco', 3, 80, UNKNOWN, FALSE, DATE '2001-01-01'),\n"
+ + " (110, 'John', 40, 'M', 'Vancouver', 2, CAST(NULL AS INT), FALSE, TRUE, DATE '2002-05-03'),\n"
+ + " (120, 'Wilma', 20, 'F', CAST(NULL AS VARCHAR(20)), 1, 5, UNKNOWN, TRUE, DATE '2005-09-07'),\n"
+ + " (130, 'Alice', 40, 'F', 'Vancouver', 2, CAST(NULL AS INT), FALSE, TRUE, DATE '2007-01-01'))\n"
+ + " as t(empno, name, deptno, gender, city, empid, age, slacker, manager, joinedat)",
ImmutableList.<String>of()));
return post;
default:
@@ -650,16 +669,15 @@ public class OptiqAssert {
}
}
- static OptiqConnection getConnection(String... schema)
+ static CalciteConnection getConnection(String... schema)
throws ClassNotFoundException, SQLException {
final List<String> schemaList = Arrays.asList(schema);
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
String suffix = schemaList.contains("spark") ? "spark=true" : "";
Connection connection =
DriverManager.getConnection("jdbc:calcite:" + suffix);
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
if (schemaList.contains("hr")) {
addSchema(rootSchema, SchemaSpec.HR);
}
@@ -676,7 +694,7 @@ public class OptiqAssert {
// always present
Util.discard(0);
}
- return optiqConnection;
+ return calciteConnection;
}
/**
@@ -690,13 +708,12 @@ public class OptiqAssert {
* @throws ClassNotFoundException
* @throws java.sql.SQLException
*/
- static OptiqConnection getConnection(SchemaSpec schemaSpec)
+ static CalciteConnection getConnection(SchemaSpec schemaSpec)
throws ClassNotFoundException, SQLException {
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- final SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ final SchemaPlus rootSchema = calciteConnection.getRootSchema();
switch (schemaSpec) {
case JDBC_FOODMART:
addSchema(rootSchema, schemaSpec);
@@ -709,8 +726,8 @@ public class OptiqAssert {
default:
throw new AssertionError("unknown schema " + schemaSpec);
}
- optiqConnection.setSchema("foodmart2");
- return optiqConnection;
+ calciteConnection.setSchema("foodmart2");
+ return calciteConnection;
}
static <F, T> Function<F, T> constantNull() {
@@ -719,7 +736,7 @@ public class OptiqAssert {
}
/**
- * Result of calling {@link OptiqAssert#that}.
+ * Result of calling {@link CalciteAssert#that}.
*/
public static class AssertThat {
private final ConnectionFactory connectionFactory;
@@ -743,13 +760,12 @@ public class OptiqAssert {
public AssertThat with(final Map<String, String> map) {
return new AssertThat(
new ConnectionFactory() {
- public OptiqConnection createConnection() throws Exception {
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
+ public CalciteConnection createConnection() throws Exception {
final Properties info = new Properties();
for (Map.Entry<String, String> entry : map.entrySet()) {
info.setProperty(entry.getKey(), entry.getValue());
}
- return (OptiqConnection) DriverManager.getConnection(
+ return (CalciteConnection) DriverManager.getConnection(
"jdbc:calcite:", info);
}
});
@@ -759,30 +775,28 @@ public class OptiqAssert {
* object. */
public AssertThat with(final String name, final Object schema) {
return with(
- new OptiqAssert.ConnectionFactory() {
- public OptiqConnection createConnection() throws Exception {
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
+ new CalciteAssert.ConnectionFactory() {
+ public CalciteConnection createConnection() throws Exception {
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema =
- optiqConnection.getRootSchema();
+ calciteConnection.getRootSchema();
rootSchema.add(name, new ReflectiveSchema(schema));
- optiqConnection.setSchema(name);
- return optiqConnection;
+ calciteConnection.setSchema(name);
+ return calciteConnection;
}
});
}
public AssertThat withModel(final String model) {
return new AssertThat(
- new OptiqAssert.ConnectionFactory() {
- public OptiqConnection createConnection() throws Exception {
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
+ new CalciteAssert.ConnectionFactory() {
+ public CalciteConnection createConnection() throws Exception {
final Properties info = new Properties();
info.setProperty("model", "inline:" + model);
- return (OptiqConnection) DriverManager.getConnection(
+ return (CalciteConnection) DriverManager.getConnection(
"jdbc:calcite:", info);
}
});
@@ -854,12 +868,13 @@ public class OptiqAssert {
return this;
}
- /** Creates a {@link OptiqConnection} and executes a callback. */
- public <T> AssertThat doWithConnection(Function<OptiqConnection, T> fn)
+ /** Creates a {@link org.apache.calcite.jdbc.CalciteConnection}
+ * and executes a callback. */
+ public <T> AssertThat doWithConnection(Function<CalciteConnection, T> fn)
throws Exception {
Connection connection = connectionFactory.createConnection();
try {
- T t = fn.apply((OptiqConnection) connection);
+ T t = fn.apply((CalciteConnection) connection);
Util.discard(t);
return AssertThat.this;
} finally {
@@ -870,7 +885,7 @@ public class OptiqAssert {
/** Creates a {@link DataContext} and executes a callback. */
public <T> AssertThat doWithDataContext(Function<DataContext, T> fn)
throws Exception {
- OptiqConnection connection = connectionFactory.createConnection();
+ CalciteConnection connection = connectionFactory.createConnection();
final DataContext dataContext = MetaImpl.createDataContext(connection);
try {
T t = fn.apply(dataContext);
@@ -906,10 +921,12 @@ public class OptiqAssert {
}
}
+ /** Connection factory. */
public interface ConnectionFactory {
- OptiqConnection createConnection() throws Exception;
+ CalciteConnection createConnection() throws Exception;
}
+ /** Connection factory that uses the same instance of connections. */
private static class PoolingConnectionFactory implements ConnectionFactory {
private final ConnectionFactory factory;
@@ -917,24 +934,27 @@ public class OptiqAssert {
this.factory = factory;
}
- public OptiqConnection createConnection() throws Exception {
+ public CalciteConnection createConnection() throws Exception {
return Pool.INSTANCE.cache.get(factory);
}
}
+ /** Connection pool. */
private static class Pool {
private static final Pool INSTANCE = new Pool();
- private final LoadingCache<ConnectionFactory, OptiqConnection> cache =
+ private final LoadingCache<ConnectionFactory, CalciteConnection> cache =
CacheBuilder.newBuilder().build(
- new CacheLoader<ConnectionFactory, OptiqConnection>() {
- public OptiqConnection load(ConnectionFactory key)
+ new CacheLoader<ConnectionFactory, CalciteConnection>() {
+ public CalciteConnection load(ConnectionFactory key)
throws Exception {
return key.createConnection();
}
});
}
+ /** Connection factory that creates connections based on a given
+ * {@link Config}. */
private static class ConfigConnectionFactory implements ConnectionFactory {
private final Config config;
@@ -952,7 +972,7 @@ public class OptiqAssert {
&& config == ((ConfigConnectionFactory) obj).config;
}
- public OptiqConnection createConnection() throws Exception {
+ public CalciteConnection createConnection() throws Exception {
switch (config) {
case REGULAR:
return getConnection("hr", "foodmart", "post");
@@ -961,7 +981,7 @@ public class OptiqAssert {
case LINGUAL:
return getConnection("lingual");
case JDBC_FOODMART:
- return getConnection(OptiqAssert.SchemaSpec.JDBC_FOODMART);
+ return getConnection(CalciteAssert.SchemaSpec.JDBC_FOODMART);
case FOODMART_CLONE:
return getConnection(SchemaSpec.CLONE_FOODMART);
case JDBC_FOODMART_WITH_LATTICE:
@@ -974,6 +994,7 @@ public class OptiqAssert {
}
}
+ /** Connection factory that delegates to an underlying factory. */
private static class DelegatingConnectionFactory
implements ConnectionFactory {
private final ConnectionFactory factory;
@@ -982,11 +1003,13 @@ public class OptiqAssert {
this.factory = factory;
}
- public OptiqConnection createConnection() throws Exception {
+ public CalciteConnection createConnection() throws Exception {
return factory.createConnection();
}
}
+ /** Connection factory that gets a connection from an underlying factory, then
+ * sets its schema. */
private static class SchemaConnectionFactory
extends DelegatingConnectionFactory {
private final String schema;
@@ -996,14 +1019,14 @@ public class OptiqAssert {
this.schema = schema;
}
- @Override
- public OptiqConnection createConnection() throws Exception {
- OptiqConnection connection = super.createConnection();
+ @Override public CalciteConnection createConnection() throws Exception {
+ CalciteConnection connection = super.createConnection();
connection.setSchema(schema);
return connection;
}
}
+ /** Fluent interface for building a query to be tested. */
public static class AssertQuery {
private final String sql;
private ConnectionFactory connectionFactory;
@@ -1231,11 +1254,13 @@ public class OptiqAssert {
}
}
+ /** Connection configuration. Basically, a set of schemas that should be
+ * instantiated in the connection. */
public enum Config {
/**
* Configuration that creates a connection with two in-memory data sets:
- * {@link net.hydromatic.optiq.test.JdbcTest.HrSchema} and
- * {@link net.hydromatic.optiq.test.JdbcTest.FoodmartSchema}.
+ * {@link org.apache.calcite.test.JdbcTest.HrSchema} and
+ * {@link org.apache.calcite.test.JdbcTest.FoodmartSchema}.
*/
REGULAR,
@@ -1250,7 +1275,7 @@ public class OptiqAssert {
* such as "customer" and "sales_fact_1997" are available. Queries
* are processed by generating Java that calls linq4j operators
* such as
- * {@link net.hydromatic.linq4j.Enumerable#where(net.hydromatic.linq4j.function.Predicate1)}.
+ * {@link org.apache.calcite.linq4j.Enumerable#where(org.apache.calcite.linq4j.function.Predicate1)}.
*/
JDBC_FOODMART,
@@ -1280,23 +1305,20 @@ public class OptiqAssert {
return new NopAssertQuery(sql);
}
- @Override
- protected Connection createConnection() throws Exception {
+ @Override protected Connection createConnection() throws Exception {
throw new AssertionError("disabled");
}
- @Override
- public AssertQuery returns(String sql, Function<ResultSet, Void> checker) {
+ @Override public AssertQuery returns(String sql,
+ Function<ResultSet, Void> checker) {
return this;
}
- @Override
- public AssertQuery throws_(String message) {
+ @Override public AssertQuery throws_(String message) {
return this;
}
- @Override
- public AssertQuery runs() {
+ @Override public AssertQuery runs() {
return this;
}
@@ -1310,18 +1332,16 @@ public class OptiqAssert {
return this;
}
- @Override
- public AssertQuery planContains(String expected) {
+ @Override public AssertQuery planContains(String expected) {
return this;
}
- @Override
- public AssertQuery planHasSql(String expected) {
+ @Override public AssertQuery planHasSql(String expected) {
return this;
}
- @Override
- public AssertQuery queryContains(Function<List, Void> predicate1) {
+ @Override public AssertQuery
+ queryContains(Function<List, Void> predicate1) {
return this;
}
}
@@ -1348,6 +1368,7 @@ public class OptiqAssert {
}
}
+ /** Specification for common test schemas. */
public enum SchemaSpec {
REFLECTIVE_FOODMART,
JDBC_FOODMART,
@@ -1359,4 +1380,4 @@ public class OptiqAssert {
}
}
-// End OptiqAssert.java
+// End CalciteAssert.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/CalciteResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteResourceTest.java b/core/src/test/java/org/apache/calcite/test/CalciteResourceTest.java
index fb81edb..7bf4eae 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteResourceTest.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteResourceTest.java
@@ -14,25 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.util.*;
+package org.apache.calcite.test;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
-import static org.eigenbase.util.Static.RESOURCE;
+import java.util.Map;
+
+import static org.apache.calcite.util.Static.RESOURCE;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertThat;
/**
- * Tests generated package org.eigenbase.resource (mostly a sanity check for
- * resgen infrastructure).
+ * Tests the generated implementation of
+ * {@link org.apache.calcite.runtime.CalciteResource} (mostly a sanity check for
+ * the resource-generation infrastructure).
*/
-public class EigenbaseResourceTest {
+public class CalciteResourceTest {
//~ Constructors -----------------------------------------------------------
- public EigenbaseResourceTest() {
+ public CalciteResourceTest() {
}
//~ Methods ----------------------------------------------------------------
@@ -48,4 +49,4 @@ public class EigenbaseResourceTest {
}
}
-// End EigenbaseResourceTest.java
+// End CalciteResourceTest.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/CalciteSqlOperatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteSqlOperatorTest.java b/core/src/test/java/org/apache/calcite/test/CalciteSqlOperatorTest.java
index ecdce14..dc87ab8 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteSqlOperatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteSqlOperatorTest.java
@@ -14,23 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
+package org.apache.calcite.test;
-import net.hydromatic.optiq.jdbc.OptiqConnection;
-
-import org.eigenbase.sql.test.SqlOperatorBaseTest;
-import org.eigenbase.sql.test.SqlTester;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.sql.test.SqlOperatorBaseTest;
+import org.apache.calcite.sql.test.SqlTester;
/**
- * Embodiment of {@link org.eigenbase.sql.test.SqlOperatorBaseTest}
+ * Embodiment of {@link org.apache.calcite.sql.test.SqlOperatorBaseTest}
* that generates SQL statements and executes them using Calcite.
*/
-public class OptiqSqlOperatorTest extends SqlOperatorBaseTest {
- private static final ThreadLocal<OptiqConnection> LOCAL =
- new ThreadLocal<OptiqConnection>() {
- @Override protected OptiqConnection initialValue() {
+public class CalciteSqlOperatorTest extends SqlOperatorBaseTest {
+ private static final ThreadLocal<CalciteConnection> LOCAL =
+ new ThreadLocal<CalciteConnection>() {
+ @Override protected CalciteConnection initialValue() {
try {
- return OptiqAssert.getConnection("hr");
+ return CalciteAssert.getConnection("hr");
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -41,9 +40,9 @@ public class OptiqSqlOperatorTest extends SqlOperatorBaseTest {
return tester(LOCAL.get());
}
- public OptiqSqlOperatorTest() {
+ public CalciteSqlOperatorTest() {
super(false, getHrTester());
}
}
-// End OptiqSqlOperatorTest.java
+// End CalciteSqlOperatorTest.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteSuite.java b/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
index 8e0dd1a..3a3ec53 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
@@ -14,27 +14,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
+package org.apache.calcite.test;
-import net.hydromatic.optiq.impl.clone.ArrayTableTest;
-import net.hydromatic.optiq.runtime.BinarySearchTest;
-import net.hydromatic.optiq.runtime.EnumerablesTest;
-import net.hydromatic.optiq.tools.FrameworksTest;
-import net.hydromatic.optiq.tools.PlannerTest;
-import net.hydromatic.optiq.util.BitSetsTest;
-import net.hydromatic.optiq.util.PartiallyOrderedSetTest;
-import net.hydromatic.optiq.util.graph.DirectedGraphTest;
-
-import org.eigenbase.relopt.RelOptUtilTest;
-import org.eigenbase.relopt.RelWriterTest;
-import org.eigenbase.relopt.volcano.VolcanoPlannerTest;
-import org.eigenbase.relopt.volcano.VolcanoPlannerTraitTest;
-import org.eigenbase.rex.RexExecutorTest;
-import org.eigenbase.sql.parser.SqlParserTest;
-import org.eigenbase.sql.test.*;
-import org.eigenbase.test.*;
-import org.eigenbase.util.*;
-import org.eigenbase.util.mapping.MappingTest;
+import org.apache.calcite.adapter.clone.ArrayTableTest;
+import org.apache.calcite.plan.RelOptUtilTest;
+import org.apache.calcite.plan.RelWriterTest;
+import org.apache.calcite.plan.volcano.VolcanoPlannerTest;
+import org.apache.calcite.plan.volcano.VolcanoPlannerTraitTest;
+import org.apache.calcite.rex.RexExecutorTest;
+import org.apache.calcite.runtime.BinarySearchTest;
+import org.apache.calcite.runtime.EnumerablesTest;
+import org.apache.calcite.sql.parser.SqlParserTest;
+import org.apache.calcite.sql.test.SqlAdvisorTest;
+import org.apache.calcite.sql.test.SqlOperatorTest;
+import org.apache.calcite.sql.test.SqlPrettyWriterTest;
+import org.apache.calcite.sql.test.SqlTypeNameTest;
+import org.apache.calcite.tools.FrameworksTest;
+import org.apache.calcite.tools.PlannerTest;
+import org.apache.calcite.util.BitSetsTest;
+import org.apache.calcite.util.ChunkListTest;
+import org.apache.calcite.util.PartiallyOrderedSetTest;
+import org.apache.calcite.util.PermutationTestCase;
+import org.apache.calcite.util.ReflectVisitorTest;
+import org.apache.calcite.util.UtilTest;
+import org.apache.calcite.util.graph.DirectedGraphTest;
+import org.apache.calcite.util.mapping.MappingTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -58,7 +62,7 @@ import org.junit.runners.Suite;
RelOptUtilTest.class,
UtilTest.class,
MappingTest.class,
- EigenbaseResourceTest.class,
+ CalciteResourceTest.class,
FilteratorTest.class,
PermutationTestCase.class,
SqlFunctionsTest.class,
@@ -69,7 +73,6 @@ import org.junit.runners.Suite;
InterpreterTest.class,
VolcanoPlannerTest.class,
HepPlannerTest.class,
- SargTest.class,
RelWriterTest.class,
RexProgramTest.class,
RexTransformerTest.class,
@@ -100,7 +103,7 @@ import org.junit.runners.Suite;
JdbcAdapterTest.class,
LinqFrontJdbcBackTest.class,
JdbcFrontJdbcBackLinqMiddleTest.class,
- OptiqSqlOperatorTest.class,
+ CalciteSqlOperatorTest.class,
LatticeTest.class,
ReflectiveSchemaTest.class,
JdbcTest.class,
@@ -117,7 +120,7 @@ import org.junit.runners.Suite;
// '-Dcalcite.test.slow=true' is specified)
FoodmartTest.class
})
-public class OptiqSuite {
+public class CalciteSuite {
}
-// End OptiqSuite.java
+// End CalciteSuite.java