DRILL-7673: View set query fails with NPE for non-existing option
closes #2043
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/SetOptionHandler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/SetOptionHandler.java
index 41a1b78..d041444 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/SetOptionHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/SetOptionHandler.java
@@ -26,6 +26,7 @@
import org.apache.drill.exec.physical.PhysicalPlan;
import org.apache.drill.exec.planner.sql.DirectPlan;
import org.apache.drill.exec.planner.sql.parser.DrillSqlSetOption;
+import org.apache.drill.exec.server.options.OptionDefinition;
import org.apache.drill.exec.server.options.OptionManager;
import org.apache.drill.exec.server.options.OptionValue;
import org.apache.drill.exec.server.options.OptionValue.OptionScope;
@@ -63,9 +64,12 @@
SqlNode optionValue = statement.getValue();
if (optionValue == null) {
+ // OptionManager.getOptionDefinition() call ensures that the specified option name is valid
+ OptionDefinition optionDefinition = optionManager.getOptionDefinition(optionName);
String value = String.valueOf(optionManager.getOption(optionName).getValue());
- return DirectPlan.createDirectPlan(context, new SetOptionViewResult(optionName, value));
+ // obtains option name from OptionDefinition to use the name as defined in the option, rather than what the user provided
+ return DirectPlan.createDirectPlan(context, new SetOptionViewResult(optionDefinition.getValidator().getOptionName(), value));
} else {
if (optionScope == OptionValue.OptionScope.SYSTEM) {
checkAdminPrivileges(context.getOptions());
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/sql/handlers/SetOptionHandlerTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/sql/handlers/SetOptionHandlerTest.java
index def1240..3f2854d 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/sql/handlers/SetOptionHandlerTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/sql/handlers/SetOptionHandlerTest.java
@@ -18,6 +18,7 @@
package org.apache.drill.exec.planner.sql.handlers;
import org.apache.drill.categories.SqlTest;
+import org.apache.drill.common.exceptions.UserRemoteException;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.compile.ClassCompilerSelector;
import org.apache.drill.test.ClusterFixture;
@@ -27,6 +28,10 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
@Category(SqlTest.class)
public class SetOptionHandlerTest extends ClusterTest {
@@ -42,11 +47,11 @@
ClassCompilerSelector.JAVA_COMPILER_DEBUG_OPTION)
.singletonString();
- boolean newValue = !Boolean.valueOf(defaultValue);
+ boolean newValue = !Boolean.parseBoolean(defaultValue);
try {
client.alterSession(ClassCompilerSelector.JAVA_COMPILER_DEBUG_OPTION, newValue);
- String changedValue = client.queryBuilder()
+ String changedValue = queryBuilder()
.sql("SELECT val from sys.options where name = '%s' limit 1",
ClassCompilerSelector.JAVA_COMPILER_DEBUG_OPTION)
.singletonString();
@@ -59,32 +64,42 @@
@Test
public void testViewSetQuery() throws Exception {
- client.testBuilder() // BIT
+ testBuilder() // BIT
.sqlQuery("SET `%s`", ExecConstants.ENABLE_ITERATOR_VALIDATION_OPTION)
.unOrdered()
.sqlBaselineQuery("SELECT name, val as value FROM sys.options where name = '%s' limit 1",
ExecConstants.ENABLE_ITERATOR_VALIDATION_OPTION)
.go();
- client.testBuilder() // BIGINT
+ testBuilder() // BIGINT
.sqlQuery("SET `%s`", ExecConstants.OUTPUT_BATCH_SIZE)
.unOrdered()
.sqlBaselineQuery("SELECT name, val as value FROM sys.options where name = '%s' limit 1",
ExecConstants.OUTPUT_BATCH_SIZE)
.go();
- client.testBuilder() // FLOAT
+ testBuilder() // FLOAT
.sqlQuery("SET `%s`", ExecConstants.OUTPUT_BATCH_SIZE_AVAIL_MEM_FACTOR)
.unOrdered()
.sqlBaselineQuery("SELECT name, val as value FROM sys.options where name = '%s' limit 1",
ExecConstants.OUTPUT_BATCH_SIZE_AVAIL_MEM_FACTOR)
.go();
- client.testBuilder() // VARCHAR
+ testBuilder() // VARCHAR
.sqlQuery("SET `%s`", ExecConstants.FILESYSTEM_PARTITION_COLUMN_LABEL)
.unOrdered()
.sqlBaselineQuery("SELECT name, val as value FROM sys.options where name = '%s' limit 1",
ExecConstants.FILESYSTEM_PARTITION_COLUMN_LABEL)
.go();
}
+
+ @Test
+ public void testViewSetWithIncorrectOption() throws Exception {
+ try {
+ run("set `non-existing option`");
+ fail();
+ } catch (UserRemoteException e) {
+ assertThat(e.getMessage(), startsWith("VALIDATION ERROR"));
+ }
+ }
}