use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class OptUtils method convert.
/**
* Converts a {@link TableField} to {@link RelDataType}.
*/
public static RelDataType convert(TableField field, RelDataTypeFactory typeFactory) {
QueryDataType fieldType = field.getType();
SqlTypeName sqlTypeName = HazelcastTypeUtils.toCalciteType(fieldType);
if (sqlTypeName == null) {
throw new IllegalStateException("Unsupported type family: " + fieldType + ", getSqlTypeName should never return null.");
}
if (sqlTypeName == SqlTypeName.OTHER) {
return convertCustomType(fieldType);
} else {
RelDataType relType = typeFactory.createSqlType(sqlTypeName);
return typeFactory.createTypeWithNullability(relType, true);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class LiteralUtils method literal.
public static Literal literal(RexNode node) {
if (node.getKind() != SqlKind.LITERAL) {
// Not a literal
return null;
}
RexLiteral literal = (RexLiteral) node;
SqlTypeName typeName = literal.getTypeName();
// Intercept DATE, TIME, TIMESTAMP types to return (Offset, Local)(Date, Time) instead of Calendar class
Object value = (DATETIME_TYPES.contains(typeName) && typeName != SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE) ? createDateTimeValue(typeName, literal) : literal.getValue();
return literal0(node.getType().getSqlTypeName(), value);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project apex-malhar by apache.
the class OperatorUtils method getFieldName.
/**
* This method gives field name for POJO class for given {@link RelDataTypeField} object.
*
* @param field field object that needs to be converted to POJO class field name
* @return Return field name from POJO class
*/
public static String getFieldName(RelDataTypeField field) {
SqlTypeName sqlTypeName = field.getType().getSqlTypeName();
String name = getValidFieldName(field);
name = (sqlTypeName == SqlTypeName.TIMESTAMP) ? (name + "Ms") : ((sqlTypeName == SqlTypeName.DATE) ? (name + "Sec") : name);
return name;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project beam by apache.
the class BeamSqlUnparseContext method toSql.
@Override
public SqlNode toSql(RexProgram program, RexNode rex) {
if (rex.getKind().equals(SqlKind.LITERAL)) {
final RexLiteral literal = (RexLiteral) rex;
SqlTypeName name = literal.getTypeName();
SqlTypeFamily family = name.getFamily();
if (SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE.equals(name)) {
TimestampString timestampString = literal.getValueAs(TimestampString.class);
return new SqlDateTimeLiteral(timestampString, POS);
} else if (SqlTypeFamily.BINARY.equals(family)) {
ByteString byteString = literal.getValueAs(ByteString.class);
BitString bitString = BitString.createFromHexString(byteString.toString(16));
return new SqlByteStringLiteral(bitString, POS);
} else if (SqlTypeFamily.CHARACTER.equals(family)) {
String escaped = ESCAPE_FOR_ZETA_SQL.translate(literal.getValueAs(String.class));
return SqlLiteral.createCharString(escaped, POS);
} else if (SqlTypeName.SYMBOL.equals(literal.getTypeName())) {
Enum symbol = literal.getValueAs(Enum.class);
if (TimeUnitRange.DOW.equals(symbol)) {
return new ReplaceLiteral(literal, POS, "DAYOFWEEK");
} else if (TimeUnitRange.DOY.equals(symbol)) {
return new ReplaceLiteral(literal, POS, "DAYOFYEAR");
} else if (TimeUnitRange.WEEK.equals(symbol)) {
return new ReplaceLiteral(literal, POS, "ISOWEEK");
}
}
} else if (rex.getKind().equals(SqlKind.DYNAMIC_PARAM)) {
final RexDynamicParam param = (RexDynamicParam) rex;
final int index = param.getIndex();
final String name = "null_param_" + index;
nullParams.put(name, param.getType());
return new NamedDynamicParam(index, POS, name);
} else if (SqlKind.SEARCH.equals(rex.getKind())) {
// Workaround CALCITE-4716
RexCall search = (RexCall) rex;
RexLocalRef ref = (RexLocalRef) search.operands.get(1);
RexLiteral literal = (RexLiteral) program.getExprList().get(ref.getIndex());
rex = search.clone(search.getType(), ImmutableList.of(search.operands.get(0), literal));
}
return super.toSql(program, rex);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project samza by apache.
the class SamzaSqlValidator method compareFieldTypes.
private boolean compareFieldTypes(RelDataType outputFieldType, SqlFieldSchema sqlFieldSchema, RelDataType selectQueryFieldType, RelSchemaProvider outputRelSchemaProvider) {
SqlTypeName outputSqlType = outputFieldType.getSqlTypeName();
SqlTypeName projectSqlType = selectQueryFieldType.getSqlTypeName();
if (projectSqlType == SqlTypeName.ANY || outputSqlType == SqlTypeName.ANY) {
return true;
} else if (outputSqlType != SqlTypeName.ROW && outputSqlType == projectSqlType) {
return true;
}
switch(outputSqlType) {
case CHAR:
return projectSqlType == SqlTypeName.VARCHAR;
case VARCHAR:
return projectSqlType == SqlTypeName.CHAR;
case BIGINT:
return projectSqlType == SqlTypeName.INTEGER;
case INTEGER:
return projectSqlType == SqlTypeName.BIGINT;
case FLOAT:
return projectSqlType == SqlTypeName.DOUBLE;
case DOUBLE:
return projectSqlType == SqlTypeName.FLOAT;
case ROW:
try {
validateOutputRecords(sqlFieldSchema.getRowSchema(), (RelRecordType) outputFieldType, (RelRecordType) selectQueryFieldType, outputRelSchemaProvider);
} catch (SamzaSqlValidatorException e) {
LOG.error("A field in select query does not match with the output schema.", e);
return false;
}
return true;
default:
return false;
}
}
Aggregations