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 2016/06/05 22:22:53 UTC
[12/12] calcite git commit: [CALCITE-1151] Fix SqlSetOption to
correctly handle SqlOperator.createCall (Sudheesh Katkam, Minji Kim)
[CALCITE-1151] Fix SqlSetOption to correctly handle SqlOperator.createCall (Sudheesh Katkam, Minji Kim)
Close apache/calcite#244
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/fa767791
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/fa767791
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/fa767791
Branch: refs/heads/master
Commit: fa76779106ce975e9893c7cd38678f0ce98d3f27
Parents: b5e6663
Author: Minji Kim <mi...@dremio.com>
Authored: Fri Jun 3 17:52:35 2016 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Sat Jun 4 21:35:30 2016 -0700
----------------------------------------------------------------------
.../org/apache/calcite/sql/SqlSetOption.java | 10 ++-
.../calcite/sql/SqlSetOptionOperatorTest.java | 76 ++++++++++++++++++++
.../org/apache/calcite/test/CalciteSuite.java | 2 +
3 files changed, 87 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/fa767791/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java b/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java
index 81a2e2c..0d20d96 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSetOption.java
@@ -60,7 +60,15 @@ import java.util.List;
*/
public class SqlSetOption extends SqlCall {
public static final SqlSpecialOperator OPERATOR =
- new SqlSpecialOperator("SET_OPTION", SqlKind.SET_OPTION);
+ new SqlSpecialOperator("SET_OPTION", SqlKind.SET_OPTION) {
+ @Override public SqlCall createCall(SqlLiteral functionQualifier,
+ SqlParserPos pos, SqlNode... operands) {
+ final SqlNode scopeNode = operands[0];
+ return new SqlSetOption(pos,
+ scopeNode == null ? null : scopeNode.toString(),
+ (SqlIdentifier) operands[1], operands[2]);
+ }
+ };
/** Scope of the assignment. Values "SYSTEM" and "SESSION" are typical. */
String scope;
http://git-wip-us.apache.org/repos/asf/calcite/blob/fa767791/core/src/test/java/org/apache/calcite/sql/SqlSetOptionOperatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/SqlSetOptionOperatorTest.java b/core/src/test/java/org/apache/calcite/sql/SqlSetOptionOperatorTest.java
new file mode 100644
index 0000000..11fff03
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/sql/SqlSetOptionOperatorTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql;
+
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for {@link SqlSetOption}.
+ */
+public class SqlSetOptionOperatorTest {
+
+ @Test public void testSqlSetOptionOperatorScopeSet() throws SqlParseException {
+ SqlNode node = parse("alter system set optionA.optionB.optionC = true");
+ checkSqlSetOptionSame(node);
+ }
+
+ public SqlNode parse(String s) throws SqlParseException {
+ return SqlParser.create(s).parseStmt();
+ }
+
+ @Test public void testSqlSetOptionOperatorSet() throws SqlParseException {
+ SqlNode node = parse("set optionA.optionB.optionC = true");
+ checkSqlSetOptionSame(node);
+ }
+
+ @Test public void testSqlSetOptionOperatorScopeReset() throws SqlParseException {
+ SqlNode node = parse("alter session reset param1.param2.param3");
+ checkSqlSetOptionSame(node);
+ }
+
+ @Test public void testSqlSetOptionOperatorReset() throws SqlParseException {
+ SqlNode node = parse("reset param1.param2.param3");
+ checkSqlSetOptionSame(node);
+ }
+
+ private static void checkSqlSetOptionSame(SqlNode node) {
+ SqlSetOption opt = (SqlSetOption) node;
+ SqlNode[] sqlNodes = new SqlNode[opt.getOperandList().size()];
+ SqlCall returned = opt.getOperator().createCall(
+ opt.getFunctionQuantifier(),
+ opt.getParserPosition(),
+ opt.getOperandList().toArray(sqlNodes));
+ assertThat((Class) opt.getClass(), equalTo((Class) returned.getClass()));
+ SqlSetOption optRet = (SqlSetOption) returned;
+ assertThat(optRet.getScope(), is(opt.getScope()));
+ assertThat(optRet.getName(), is(opt.getName()));
+ assertThat(optRet.getFunctionQuantifier(), is(opt.getFunctionQuantifier()));
+ assertThat(optRet.getParserPosition(), is(opt.getParserPosition()));
+ assertThat(optRet.getValue(), is(opt.getValue()));
+ assertThat(optRet.toString(), is(opt.toString()));
+ }
+
+}
+
+// End SqlSetOptionOperatorTest.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/fa767791/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 e864910..c43a76e 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
@@ -29,6 +29,7 @@ import org.apache.calcite.rel.rel2sql.RelToSqlConverterTest;
import org.apache.calcite.rex.RexExecutorTest;
import org.apache.calcite.runtime.BinarySearchTest;
import org.apache.calcite.runtime.EnumerablesTest;
+import org.apache.calcite.sql.SqlSetOptionOperatorTest;
import org.apache.calcite.sql.parser.SqlParserTest;
import org.apache.calcite.sql.parser.SqlUnParserTest;
import org.apache.calcite.sql.test.SqlAdvisorTest;
@@ -97,6 +98,7 @@ import org.junit.runners.Suite;
// medium tests (above 0.1s)
SqlParserTest.class,
SqlUnParserTest.class,
+ SqlSetOptionOperatorTest.class,
SqlPrettyWriterTest.class,
SqlValidatorTest.class,
SqlAdvisorTest.class,