use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project flink by apache.
the class SqlValidatorImpl method validateCall.
public void validateCall(SqlCall call, SqlValidatorScope scope) {
final SqlOperator operator = call.getOperator();
if ((call.operandCount() == 0) && (operator.getSyntax() == SqlSyntax.FUNCTION_ID) && !call.isExpanded() && !this.config.sqlConformance().allowNiladicParentheses()) {
// SqlIdentifier.)
throw handleUnresolvedFunction(call, (SqlFunction) operator, ImmutableList.of(), null);
}
SqlValidatorScope operandScope = scope.getOperandScope(call);
if (operator instanceof SqlFunction && ((SqlFunction) operator).getFunctionType() == SqlFunctionCategory.MATCH_RECOGNIZE && !(operandScope instanceof MatchRecognizeScope)) {
throw newValidationError(call, Static.RESOURCE.functionMatchRecognizeOnly(call.toString()));
}
// Delegate validation to the operator.
operator.validateCall(call, this, scope, operandScope);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project flink by apache.
the class OverConvertRule method createBound.
private RexWindowBound createBound(ConvertContext context, Expression bound, SqlKind sqlKind) {
if (bound instanceof CallExpression) {
CallExpression callExpr = (CallExpression) bound;
FunctionDefinition func = callExpr.getFunctionDefinition();
if (BuiltInFunctionDefinitions.UNBOUNDED_ROW.equals(func) || BuiltInFunctionDefinitions.UNBOUNDED_RANGE.equals(func)) {
SqlNode unbounded = sqlKind.equals(SqlKind.PRECEDING) ? SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO) : SqlWindow.createUnboundedFollowing(SqlParserPos.ZERO);
return RexWindowBound.create(unbounded, null);
} else if (BuiltInFunctionDefinitions.CURRENT_ROW.equals(func) || BuiltInFunctionDefinitions.CURRENT_RANGE.equals(func)) {
SqlNode currentRow = SqlWindow.createCurrentRow(SqlParserPos.ZERO);
return RexWindowBound.create(currentRow, null);
} else {
throw new IllegalArgumentException("Unexpected expression: " + bound);
}
} else if (bound instanceof ValueLiteralExpression) {
RelDataType returnType = context.getTypeFactory().createFieldTypeFromLogicalType(new DecimalType(true, 19, 0));
SqlOperator sqlOperator = new SqlPostfixOperator(sqlKind.name(), sqlKind, 2, new OrdinalReturnTypeInference(0), null, null);
SqlNode[] operands = new SqlNode[] { SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO) };
SqlNode node = new SqlBasicCall(sqlOperator, operands, SqlParserPos.ZERO);
ValueLiteralExpression literalExpr = (ValueLiteralExpression) bound;
RexNode literalRexNode = literalExpr.getValueAs(BigDecimal.class).map(v -> context.getRelBuilder().literal(v)).orElse(context.getRelBuilder().literal(extractValue(literalExpr, Object.class)));
List<RexNode> expressions = new ArrayList<>();
expressions.add(literalRexNode);
RexNode rexNode = context.getRelBuilder().getRexBuilder().makeCall(returnType, sqlOperator, expressions);
return RexWindowBound.create(node, rexNode);
} else {
throw new TableException("Unexpected expression: " + bound);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project flink by apache.
the class RexNodeJsonDeserializer method deserializeInternalFunction.
private static SqlOperator deserializeInternalFunction(String internalName, SqlSyntax syntax, SerdeContext serdeContext) {
// Try $FUNC$1
final Optional<SqlOperator> internalOperator = lookupOptionalSqlOperator(FunctionIdentifier.of(internalName), syntax, serdeContext, false);
if (internalOperator.isPresent()) {
return internalOperator.get();
}
// Try FUNC
final String publicName = BuiltInSqlOperator.extractNameFromQualifiedName(internalName);
final Optional<SqlOperator> latestOperator = lookupOptionalSqlOperator(FunctionIdentifier.of(publicName), syntax, serdeContext, true);
if (latestOperator.isPresent()) {
return latestOperator.get();
}
throw new TableException(String.format("Could not resolve internal system function '%s'. " + "This is a bug, please file an issue.", internalName));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project flink by apache.
the class RexNodeJsonDeserializer method deserializeCatalogFunction.
private static SqlOperator deserializeCatalogFunction(JsonNode jsonNode, SqlSyntax syntax, SerdeContext serdeContext) {
final CatalogPlanRestore restoreStrategy = serdeContext.getConfiguration().get(PLAN_RESTORE_CATALOG_OBJECTS);
final FunctionIdentifier identifier = FunctionIdentifier.of(ObjectIdentifierJsonDeserializer.deserialize(jsonNode.required(FIELD_NAME_CATALOG_NAME).asText(), serdeContext));
switch(restoreStrategy) {
case ALL:
{
final Optional<SqlOperator> lookupOperator = lookupOptionalSqlOperator(identifier, syntax, serdeContext, false);
if (lookupOperator.isPresent()) {
return lookupOperator.get();
} else if (jsonNode.has(FIELD_NAME_CLASS)) {
return deserializeFunctionClass(jsonNode, serdeContext);
}
throw missingFunctionFromCatalog(identifier, false);
}
case ALL_ENFORCED:
{
if (jsonNode.has(FIELD_NAME_CLASS)) {
return deserializeFunctionClass(jsonNode, serdeContext);
}
final Optional<SqlOperator> lookupOperator = lookupOptionalSqlOperator(identifier, syntax, serdeContext, false);
if (lookupOperator.map(RexNodeJsonDeserializer::isTemporary).orElse(false)) {
return lookupOperator.get();
}
throw lookupDisabled(identifier);
}
case IDENTIFIER:
final Optional<SqlOperator> lookupOperator = lookupOptionalSqlOperator(identifier, syntax, serdeContext, true);
if (lookupOperator.isPresent()) {
return lookupOperator.get();
} else {
throw missingFunctionFromCatalog(identifier, true);
}
default:
throw new TableException("Unsupported restore strategy: " + restoreStrategy);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project flink by apache.
the class RexNodeJsonDeserializer method deserializeCall.
private static RexNode deserializeCall(JsonNode jsonNode, SerdeContext serdeContext) throws IOException {
final SqlOperator operator = deserializeSqlOperator(jsonNode, serdeContext);
final ArrayNode operandNodes = (ArrayNode) jsonNode.get(FIELD_NAME_OPERANDS);
final List<RexNode> rexOperands = new ArrayList<>();
for (JsonNode node : operandNodes) {
rexOperands.add(deserialize(node, serdeContext));
}
final RelDataType callType;
if (jsonNode.has(FIELD_NAME_TYPE)) {
final JsonNode typeNode = jsonNode.get(FIELD_NAME_TYPE);
callType = RelDataTypeJsonDeserializer.deserialize(typeNode, serdeContext);
} else {
callType = serdeContext.getRexBuilder().deriveReturnType(operator, rexOperands);
}
return serdeContext.getRexBuilder().makeCall(callType, operator, rexOperands);
}
Aggregations