use of org.apache.calcite.sql.SqlLiteral 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.calcite.sql.SqlLiteral in project drill by apache.
the class DropAliasHandler method getPlan.
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException, IOException {
checkAliasesEnabled();
SqlDropAlias node = unwrap(sqlNode, SqlDropAlias.class);
String alias = SchemaPath.getCompoundPath(node.getAlias().names.toArray(new String[0])).toExpr();
String aliasTarget = ((SqlLiteral) node.getAliasKind()).toValue();
AliasRegistry aliasRegistry = getAliasRegistry(aliasTarget);
Aliases aliases = getAliases(node, aliasRegistry);
boolean checkIfExists = ((SqlLiteral) node.getIfExists()).booleanValue();
boolean removed = aliases.remove(alias);
if (!removed && !checkIfExists) {
throw UserException.validationError().message("No alias found with given name [%s]", alias).build(logger);
}
String message = removed ? String.format("%s alias '%s' dropped successfully", StringUtils.capitalize(aliasTarget.toLowerCase(Locale.ROOT)), alias) : String.format("No %s alias found with given name [%s]", aliasTarget.toLowerCase(Locale.ROOT), alias);
return DirectPlan.createDirectPlan(context, removed, message);
}
use of org.apache.calcite.sql.SqlLiteral in project flink by apache.
the class SqlCastFunction method inferReturnType.
// ~ Methods ----------------------------------------------------------------
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
assert opBinding.getOperandCount() == 2;
RelDataType ret = opBinding.getOperandType(1);
RelDataType firstType = opBinding.getOperandType(0);
ret = opBinding.getTypeFactory().createTypeWithNullability(ret, firstType.isNullable());
if (opBinding instanceof SqlCallBinding) {
SqlCallBinding callBinding = (SqlCallBinding) opBinding;
SqlNode operand0 = callBinding.operand(0);
// to them using the type they are casted to.
if (((operand0 instanceof SqlLiteral) && (((SqlLiteral) operand0).getValue() == null)) || (operand0 instanceof SqlDynamicParam)) {
final SqlValidatorImpl validator = (SqlValidatorImpl) callBinding.getValidator();
validator.setValidatedNodeType(operand0, ret);
}
}
return ret;
}
use of org.apache.calcite.sql.SqlLiteral in project flink by apache.
the class FlinkCalciteSqlValidator method validateJoin.
@Override
protected void validateJoin(SqlJoin join, SqlValidatorScope scope) {
// temporarily forbid the common predicates until the problem is fixed (see FLINK-7865).
if (join.getJoinType() == JoinType.LEFT && SqlUtil.stripAs(join.getRight()).getKind() == SqlKind.COLLECTION_TABLE) {
SqlNode right = SqlUtil.stripAs(join.getRight());
if (right instanceof SqlBasicCall) {
SqlBasicCall call = (SqlBasicCall) right;
SqlNode operand0 = call.operand(0);
if (operand0 instanceof SqlBasicCall && ((SqlBasicCall) operand0).getOperator() instanceof SqlWindowTableFunction) {
return;
}
}
final SqlNode condition = join.getCondition();
if (condition != null && (!SqlUtil.isLiteral(condition) || ((SqlLiteral) condition).getValueAs(Boolean.class) != Boolean.TRUE)) {
throw new ValidationException(String.format("Left outer joins with a table function do not accept a predicate such as %s. " + "Only literal TRUE is accepted.", condition));
}
}
super.validateJoin(join, scope);
}
use of org.apache.calcite.sql.SqlLiteral in project hazelcast by hazelcast.
the class LiteralUtils method literal.
public static Literal literal(SqlNode node) {
if (node.getKind() != SqlKind.LITERAL) {
// Not a literal
return null;
}
SqlLiteral literal = (SqlLiteral) node;
SqlTypeName typeName = literal.getTypeName();
Object value = CHAR_TYPES.contains(typeName) ? literal.toValue() : literal.getValue();
return literal0(typeName, value);
}
Aggregations