use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class LogicalPlanner method verifyJoin.
/**
* @return the foreign key column if this is a foreign key join
*/
private Optional<Expression> verifyJoin(final JoinInfo joinInfo, final PlanNode leftNode, final PlanNode rightNode) {
final JoinType joinType = joinInfo.getType();
final Expression leftExpression = joinInfo.getLeftJoinExpression();
final Expression rightExpression = joinInfo.getRightJoinExpression();
if (leftNode.getNodeOutputType() == DataSourceType.KSTREAM) {
if (rightNode.getNodeOutputType() == DataSourceType.KTABLE) {
verifyStreamTableJoin(joinInfo, rightNode);
}
// stream-stream join detected: nothing to verify
} else {
if (rightNode.getNodeOutputType() == DataSourceType.KSTREAM) {
throw new KsqlException(String.format("Invalid join order:" + " table-stream joins are not supported; only stream-table joins. Got %s %s %s.", joinInfo.getLeftSource().getDataSource().getName().text(), joinType, joinInfo.getRightSource().getDataSource().getName().text()));
}
if (joinOnNonKeyAttribute(rightExpression, rightNode, joinInfo.getRightSource())) {
throw new KsqlException(String.format("Invalid join condition:" + " table-table joins require to join on the primary key of the right input" + " table. Got %s = %s.", joinInfo.getFlippedLeftJoinExpression(), joinInfo.getFlippedRightJoinExpression()));
}
if (joinOnNonKeyAttribute(leftExpression, leftNode, joinInfo.getLeftSource())) {
return verifyForeignKeyJoin(joinInfo, leftNode, rightNode);
} else {
// primary key join detected
final SqlType leftKeyType = Iterables.getOnlyElement(leftNode.getSchema().key()).type();
final SqlType rightKeyType = Iterables.getOnlyElement(rightNode.getSchema().key()).type();
verifyJoinConditionTypes(leftKeyType, rightKeyType, leftExpression, rightExpression, joinInfo.hasFlippedJoinCondition());
}
}
return Optional.empty();
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class SqlTypeParser method getType.
public Type getType(final SqlBaseParser.TypeContext type) {
final Optional<NodeLocation> location = ParserUtil.getLocation(type);
final SqlType sqlType = getSqlType(type);
return new Type(location, sqlType);
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class SqlTypeParser method getSqlType.
private SqlType getSqlType(final SqlBaseParser.TypeContext type) {
if (type.baseType() != null) {
final String baseType = baseTypeToString(type.baseType());
if (SqlPrimitiveType.isPrimitiveTypeName(baseType)) {
return SqlPrimitiveType.of(baseType);
} else {
return typeRegistry.resolveType(baseType).orElseThrow(() -> new KsqlException("Cannot resolve unknown type: " + baseType));
}
}
if (type.DECIMAL() != null) {
return SqlDecimal.of(ParserUtil.processIntegerNumber(type.number(0), "DECIMAL(PRECISION)"), ParserUtil.processIntegerNumber(type.number(1), "DECIMAL(SCALE)"));
}
if (type.ARRAY() != null) {
return SqlArray.of(getSqlType(type.type(0)));
}
if (type.MAP() != null) {
return SqlMap.of(getSqlType(type.type(0)), getSqlType(type.type(1)));
}
if (type.STRUCT() != null) {
final SqlStruct.Builder builder = SqlStruct.builder();
for (int i = 0; i < type.identifier().size(); i++) {
final String fieldName = ParserUtil.getIdentifierText(type.identifier(i));
final SqlType fieldType = getSqlType(type.type(i));
builder.field(fieldName, fieldType);
}
return builder.build();
}
throw new IllegalArgumentException("Unsupported type specification: " + type.getText());
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class RegisterTypeFactory method create.
public RegisterTypeCommand create(final RegisterType statement) {
final String name = statement.getName();
final boolean ifNotExists = statement.getIfNotExists();
final SqlType type = statement.getType().getSqlType();
if (!ifNotExists && metaStore.resolveType(name).isPresent()) {
throw new KsqlException("Cannot register custom type '" + name + "' " + "since it is already registered with type: " + metaStore.resolveType(name).get());
}
return new RegisterTypeCommand(type, name);
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class MaxAggFunctionFactory method createAggregateFunction.
@Override
public KsqlAggregateFunction createAggregateFunction(final List<SqlArgument> argTypeList, final AggregateFunctionInitArguments initArgs) {
KsqlPreconditions.checkArgument(argTypeList.size() == 1, "expected exactly one argument to aggregate MAX function");
final SqlType argSchema = argTypeList.get(0).getSqlTypeOrThrow();
switch(argSchema.baseType()) {
case INTEGER:
return new IntegerMaxKudaf(FUNCTION_NAME, initArgs.udafIndex());
case BIGINT:
return new LongMaxKudaf(FUNCTION_NAME, initArgs.udafIndex());
case DOUBLE:
return new DoubleMaxKudaf(FUNCTION_NAME, initArgs.udafIndex());
case DECIMAL:
return new DecimalMaxKudaf(FUNCTION_NAME, initArgs.udafIndex(), argSchema);
default:
throw new KsqlException("No Max aggregate function with " + argTypeList.get(0) + " " + " argument type exists!");
}
}
Aggregations