use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project druid by druid-io.
the class OperatorConversions method toPostAggregator.
/**
* Translate a Calcite {@code RexNode} to a Druid PostAggregator
*
* @param plannerContext SQL planner context
* @param rowSignature signature of the rows to be extracted from
* @param rexNode expression meant to be applied on top of the rows
* @param postAggregatorVisitor visitor that manages postagg names and tracks postaggs that were created
* by the translation
*
* @return rexNode referring to fields in rowOrder, or null if not possible
*/
@Nullable
public static PostAggregator toPostAggregator(final PlannerContext plannerContext, final RowSignature rowSignature, final RexNode rexNode, final PostAggregatorVisitor postAggregatorVisitor) {
final SqlKind kind = rexNode.getKind();
if (kind == SqlKind.INPUT_REF) {
// Translate field references.
final RexInputRef ref = (RexInputRef) rexNode;
final String columnName = rowSignature.getColumnName(ref.getIndex());
if (columnName == null) {
throw new ISE("PostAggregator referred to nonexistent index[%d]", ref.getIndex());
}
return new FieldAccessPostAggregator(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), columnName);
} else if (rexNode instanceof RexCall) {
final SqlOperator operator = ((RexCall) rexNode).getOperator();
final SqlOperatorConversion conversion = plannerContext.getOperatorTable().lookupOperatorConversion(operator);
if (conversion == null) {
return null;
} else {
return conversion.toPostAggregator(plannerContext, rowSignature, rexNode, postAggregatorVisitor);
}
} else if (kind == SqlKind.LITERAL) {
return null;
} else {
throw new IAE("Unknown rexnode kind: " + kind);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project druid by druid-io.
the class Expressions method rexCallToDruidExpression.
private static DruidExpression rexCallToDruidExpression(final PlannerContext plannerContext, final RowSignature rowSignature, final RexNode rexNode, final PostAggregatorVisitor postAggregatorVisitor) {
final SqlOperator operator = ((RexCall) rexNode).getOperator();
final SqlOperatorConversion conversion = plannerContext.getOperatorTable().lookupOperatorConversion(operator);
if (conversion == null) {
plannerContext.setPlanningError("SQL query requires '%s' operator that is not supported.", operator.getName());
return null;
} else {
if (postAggregatorVisitor != null) {
// try making postagg first
PostAggregator postAggregator = conversion.toPostAggregator(plannerContext, rowSignature, rexNode, postAggregatorVisitor);
if (postAggregator != null) {
postAggregatorVisitor.addPostAgg(postAggregator);
String exprName = postAggregator.getName();
return DruidExpression.ofColumn(postAggregator.getType(rowSignature), exprName);
}
}
DruidExpression expression = conversion.toDruidExpressionWithPostAggOperands(plannerContext, rowSignature, rexNode, postAggregatorVisitor);
return expression;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project druid by druid-io.
the class DruidConvertletTable method createConvertletMap.
private static Map<SqlOperator, SqlRexConvertlet> createConvertletMap(final PlannerContext plannerContext) {
final SqlRexConvertlet currentTimestampAndFriends = new CurrentTimestampAndFriendsConvertlet(plannerContext);
final Map<SqlOperator, SqlRexConvertlet> table = new HashMap<>();
for (SqlOperator operator : CURRENT_TIME_CONVERTLET_OPERATORS) {
table.put(operator, currentTimestampAndFriends);
}
return table;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project hazelcast by hazelcast.
the class HazelcastSqlToRelConverter method convertBetween.
/**
* Convert "val BETWEEN lower_bound AND upper_bound" expression to
* 1. If ASYMMETRIC : "val >= lower_bound AND val =< upper_bound" expression. Default mode.
* 2. If SYMMETRIC : "(val >= lower_bound AND val =< upper_bound) OR (val <= lower_bound AND val >= upper_bound)"
* expression
*/
public RexNode convertBetween(SqlCall call, Blackboard blackboard) {
SqlOperator currentOperator = call.getOperator();
assert currentOperator instanceof HazelcastBetweenOperator;
final RexBuilder rexBuilder = getRexBuilder();
final HazelcastBetweenOperator betweenOp = (HazelcastBetweenOperator) currentOperator;
final List<RexNode> list = convertExpressionList(rexBuilder, blackboard, call.getOperandList(), betweenOp.getOperandTypeChecker().getConsistency());
final RexNode valueOperand = list.get(SqlBetweenOperator.VALUE_OPERAND);
final RexNode lowerOperand = list.get(SqlBetweenOperator.LOWER_OPERAND);
final RexNode upperOperand = list.get(SqlBetweenOperator.UPPER_OPERAND);
RexNode ge1 = rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN_OR_EQUAL, valueOperand, lowerOperand);
RexNode le1 = rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN_OR_EQUAL, valueOperand, upperOperand);
RexNode and1 = rexBuilder.makeCall(SqlStdOperatorTable.AND, ge1, le1);
RexNode res;
final SqlBetweenOperator.Flag symmetric = betweenOp.getFlag();
switch(symmetric) {
case ASYMMETRIC:
res = and1;
break;
case SYMMETRIC:
RexNode ge2 = rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN_OR_EQUAL, valueOperand, upperOperand);
RexNode le2 = rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN_OR_EQUAL, valueOperand, lowerOperand);
RexNode and2 = rexBuilder.makeCall(SqlStdOperatorTable.AND, ge2, le2);
res = rexBuilder.makeCall(SqlStdOperatorTable.OR, and1, and2);
break;
default:
throw Util.unexpected(symmetric);
}
if (betweenOp.isNegated()) {
res = rexBuilder.makeCall(SqlStdOperatorTable.NOT, res);
}
return res;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project hazelcast by hazelcast.
the class HazelcastCallBinding method newValidationSignatureError.
@Override
public CalciteException newValidationSignatureError() {
SqlOperator operator = getOperator();
SqlValidator validator = getValidator();
SqlCall call = getCall();
String operandTypes = getOperandTypes(validator, call, getScope());
Resources.ExInst<SqlValidatorException> error;
String operatorName = '\'' + operator.getName() + '\'';
switch(operator.getSyntax()) {
case FUNCTION:
case FUNCTION_STAR:
case FUNCTION_ID:
error = RESOURCES.invalidFunctionOperands(operatorName, operandTypes);
break;
default:
error = RESOURCES.invalidOperatorOperands(operatorName, operandTypes);
}
return validator.newValidationError(call, error);
}
Aggregations