org.apache.calcite.sql.SqlSetOption Java Examples
The following examples show how to use
org.apache.calcite.sql.SqlSetOption.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Validator.java From AthenaX with Apache License 2.0 | 5 votes |
/** * Extract options and jars from the queries. */ @VisibleForTesting void extract(SqlNodeList query) { for (SqlNode n : query) { if (n instanceof SqlSetOption) { extract((SqlSetOption) n); } else if (n instanceof SqlCreateFunction) { extract((SqlCreateFunction) n); } } }
Example #2
Source File: Validator.java From AthenaX with Apache License 2.0 | 5 votes |
private void extract(SqlSetOption node) { Object value = unwrapConstant(node.getValue()); String property = node.getName().toString(); Preconditions.checkArgument(!"SYSTEM".equals(node.getScope()), "cannot set properties at the system level"); conf.setProperty(property, value); }
Example #3
Source File: SetOptionHandler.java From Bats with Apache License 2.0 | 4 votes |
@Override public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, ForemanSetupException { final SqlSetOption option = unwrap(sqlNode, SqlSetOption.class); final SqlNode value = option.getValue(); if (value != null && !(value instanceof SqlLiteral)) { throw UserException.validationError() .message("Drill does not support assigning non-literal values in SET statements.") .build(logger); } final QueryOptionManager options = context.getOptions(); final String scope = option.getScope(); final OptionValue.OptionScope optionScope; if (scope == null) { // No scope mentioned assumed SESSION optionScope = OptionScope.SESSION; } else { switch (scope.toLowerCase()) { case "session": optionScope = OptionScope.SESSION; // Skip writing profiles for "ALTER SESSION SET" queries if (options.getBoolean(ExecConstants.SKIP_ALTER_SESSION_QUERY_PROFILE)) { logger.debug("Will not write profile for ALTER SESSION SET ... "); context.skipWritingProfile(true); } break; case "system": optionScope = OptionScope.SYSTEM; break; default: throw UserException.validationError() .message("Invalid OPTION scope %s. Scope must be SESSION or SYSTEM.", scope) .build(logger); } } if (optionScope == OptionScope.SYSTEM) { // If the user authentication is enabled, make sure the user who is trying to change the system option has // administrative privileges. if (context.isUserAuthenticationEnabled() && !ImpersonationUtil.hasAdminPrivileges( context.getQueryUserName(), ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(options), ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(options))) { throw UserException.permissionError() .message("Not authorized to change SYSTEM options.") .build(logger); } } final String optionName = option.getName().toString(); // Currently, we convert multi-part identifier to a string. final OptionManager chosenOptions = options.getOptionManager(optionScope); if (value != null) { // SET option final Object literalObj = sqlLiteralToObject((SqlLiteral) value); chosenOptions.setLocalOption(optionName, literalObj); } else { // RESET option if ("ALL".equalsIgnoreCase(optionName)) { chosenOptions.deleteAllLocalOptions(); } else { chosenOptions.deleteLocalOption(optionName); } } return DirectPlan.createDirectPlan(context, true, String.format("%s updated.", optionName)); }
Example #4
Source File: SqlAlterTableSetOption.java From dremio-oss with Apache License 2.0 | 4 votes |
public SqlAlterTableSetOption(SqlParserPos pos, SqlIdentifier table, SqlSetOption sqlSetOption) { super(pos, sqlSetOption.getScope(), sqlSetOption.getName(), sqlSetOption.getValue()); this.table = table; }
Example #5
Source File: SetOptionHandler.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException { final OptionValidatorListing optionValidatorProvider = session.getOptions().getOptionValidatorListing(); final QueryOptionManager queryOptionManager = new QueryOptionManager(optionValidatorProvider); final OptionManager options = OptionManagerWrapper.Builder.newBuilder() .withOptionManager(new DefaultOptionManager(optionValidatorProvider)) .withOptionManager(new EagerCachingOptionManager(context.getSystemOptionManager())) .withOptionManager(session.getSessionOptionManager()) .withOptionManager(queryOptionManager) .build(); final SqlSetOption option = SqlNodeUtil.unwrap(sqlNode, SqlSetOption.class); final String name = option.getName().toString(); final SqlNode value = option.getValue(); if (value != null && !(value instanceof SqlLiteral)) { throw UserException.validationError() .message("Dremio does not support assigning non-literal values in SET statements.") .build(logger); } final String scope = option.getScope(); final OptionValue.OptionType type; if (scope == null) { // No scope mentioned assumed SESSION type = OptionType.SESSION; } else { switch (scope.toLowerCase()) { case "session": type = OptionType.SESSION; break; case "system": type = OptionType.SYSTEM; break; default: throw UserException.validationError() .message("Invalid OPTION scope %s. Scope must be SESSION or SYSTEM.", scope) .build(logger); } } // Currently, we convert multi-part identifier to a string. if (value != null) { // SET option final OptionValue optionValue = createOptionValue(name, type, (SqlLiteral) value); options.setOption(optionValue); } else { // RESET option if ("ALL".equalsIgnoreCase(name)) { session.setDefaultSchemaPath(null); options.deleteAllOptions(type); } else { options.deleteOption(name, type); } } return Collections.singletonList(SimpleCommandResult.successful("%s updated.", name)); }