use of org.apache.drill.exec.server.options.OptionDefinition in project drill by apache.
the class SetOptionHandler method getPlan.
/**
* Handles {@link DrillSqlSetOption} query
*/
@Override
public final PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException {
// sqlNode could contain DrillSqlResetOption or DrillSqlSetOption, depends on parsed statement
SqlSetOption statement = unwrap(sqlNode, SqlSetOption.class);
OptionScope optionScope = getScope(statement, context.getOptions());
OptionManager optionManager = context.getOptions().getOptionManager(optionScope);
String optionName = statement.getName().toString();
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());
// 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());
}
if (!(optionValue instanceof SqlLiteral)) {
throw UserException.validationError().message("Drill does not support assigning non-literal values in SET statements.").build(logger);
}
optionManager.setLocalOption(optionName, sqlLiteralToObject((SqlLiteral) optionValue));
return DirectPlan.createDirectPlan(context, true, String.format("%s updated.", optionName));
}
}
use of org.apache.drill.exec.server.options.OptionDefinition in project drill by apache.
the class TestInboundImpersonationPrivileges method checkPrivileges.
private static boolean checkPrivileges(final String proxyName, final String targetName) {
OptionDefinition optionDefinition = SystemOptionManager.createDefaultOptionDefinitions().get(ExecConstants.IMPERSONATION_POLICIES_KEY);
ExecConstants.IMPERSONATION_POLICY_VALIDATOR.validate(OptionValue.create(optionDefinition.getMetaData().getAccessibleScopes(), ExecConstants.IMPERSONATION_POLICIES_KEY, IMPERSONATION_POLICIES, OptionValue.OptionScope.SYSTEM), optionDefinition.getMetaData(), null);
try {
return InboundImpersonationManager.hasImpersonationPrivileges(proxyName, targetName, IMPERSONATION_POLICIES);
} catch (final Exception e) {
logger.error("Failed to check impersonation privileges.", e);
return false;
}
}
use of org.apache.drill.exec.server.options.OptionDefinition in project drill by axbaretto.
the class TestInboundImpersonationPrivileges method checkPrivileges.
private static boolean checkPrivileges(final String proxyName, final String targetName) {
OptionDefinition optionDefinition = SystemOptionManager.createDefaultOptionDefinitions().get(ExecConstants.IMPERSONATION_POLICIES_KEY);
ExecConstants.IMPERSONATION_POLICY_VALIDATOR.validate(OptionValue.create(optionDefinition.getMetaData().getAccessibleScopes(), ExecConstants.IMPERSONATION_POLICIES_KEY, IMPERSONATION_POLICIES, OptionValue.OptionScope.SYSTEM), optionDefinition.getMetaData(), null);
try {
return InboundImpersonationManager.hasImpersonationPrivileges(proxyName, targetName, IMPERSONATION_POLICIES);
} catch (final Exception e) {
logger.error("Failed to check impersonation privileges.", e);
return false;
}
}
use of org.apache.drill.exec.server.options.OptionDefinition in project drill by axbaretto.
the class TestConfigLinkage method testDefaultInternalValue.
@Test
public void testDefaultInternalValue() throws Exception {
OptionDefinition optionDefinition = createMockPropOptionDefinition();
FixtureBuilder builder = ClusterFixture.builder().configProperty(ExecConstants.bootDefaultFor(MOCK_PROPERTY), "a").putDefinition(optionDefinition);
try (ClusterFixture cluster = builder.build();
ClientFixture client = cluster.clientFixture()) {
String mockProp = client.queryBuilder().sql("SELECT string_val FROM sys.%s where name='%s'", SystemTable.INTERNAL_OPTIONS.getTableName(), MOCK_PROPERTY).singletonString();
String mockProp2 = client.queryBuilder().sql("SELECT val FROM sys.%s where name='%s'", SystemTable.INTERNAL_OPTIONS_VAL.getTableName(), MOCK_PROPERTY).singletonString();
assertEquals("a", mockProp);
assertEquals("a", mockProp2);
}
}
Aggregations