Java Code Examples for org.apache.calcite.rel.type.RelDataTypeFactoryImpl#JavaType

The following examples show how to use org.apache.calcite.rel.type.RelDataTypeFactoryImpl#JavaType . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlUserDefinedTableMacro.java    From Bats with Apache License 2.0 6 votes vote down vote up
private static Object coerce(Object o, RelDataType type) {
  if (o == null) {
    return null;
  }
  if (!(type instanceof RelDataTypeFactoryImpl.JavaType)) {
    return null;
  }
  final RelDataTypeFactoryImpl.JavaType javaType =
      (RelDataTypeFactoryImpl.JavaType) type;
  final Class<?> clazz = javaType.getJavaClass();
  //noinspection unchecked
  if (clazz.isAssignableFrom(o.getClass())) {
    return o;
  }
  if (clazz == String.class && o instanceof NlsString) {
    return ((NlsString) o).getValue();
  }
  return null;
}
 
Example 2
Source File: SqlUserDefinedAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
private RelDataType toSql(RelDataType type) {
  if (type instanceof RelDataTypeFactoryImpl.JavaType
      && ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass()
      == Object.class) {
    return typeFactory.createTypeWithNullability(
        typeFactory.createSqlType(SqlTypeName.ANY), true);
  }
  return JavaTypeFactoryImpl.toSql(typeFactory, type);
}
 
Example 3
Source File: CalciteCatalogReader.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static RelDataType toSql(RelDataTypeFactory typeFactory,
    RelDataType type) {
  if (type instanceof RelDataTypeFactoryImpl.JavaType
      && ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass()
      == Object.class) {
    return typeFactory.createTypeWithNullability(
        typeFactory.createSqlType(SqlTypeName.ANY), true);
  }
  return JavaTypeFactoryImpl.toSql(typeFactory, type);
}
 
Example 4
Source File: DremioCatalogReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private RelDataType toSql(RelDataType type) {
  if (type instanceof RelDataTypeFactoryImpl.JavaType
      && ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass()
      == Object.class) {
    return typeFactory.createTypeWithNullability(
        typeFactory.createSqlType(SqlTypeName.ANY), true);
  }
  return typeFactory.toSql(type);
}
 
Example 5
Source File: SamzaSqlValidator.java    From samza with Apache License 2.0 5 votes vote down vote up
private RelDataType getCalciteSqlFieldType(RelDataType fieldType) {
  RelDataType sqlFieldType;

  // JavaTypes are relevant for Udf argument and return types
  // TODO: Support UDF argument validation. Currently, only return types are validated and argument types are
  //  validated during run-time.
  if (fieldType instanceof RelDataTypeFactoryImpl.JavaType) {
    sqlFieldType = new SamzaSqlJavaTypeFactoryImpl().toSql(fieldType);
  } else {
    sqlFieldType = fieldType;
  }

  return sqlFieldType;
}
 
Example 6
Source File: PlanExecutor.java    From quark with Apache License 2.0 5 votes vote down vote up
private static String getTypeName(RelDataType type) {
  SqlTypeName sqlTypeName = type.getSqlTypeName();
  if (type instanceof RelDataTypeFactoryImpl.JavaType) {
    // We'd rather print "INTEGER" than "JavaType(int)".
    return sqlTypeName.getName();
  }
  switch (sqlTypeName) {
    case INTERVAL_YEAR_MONTH:
      // e.g. "INTERVAL_MONTH" or "INTERVAL_YEAR_MONTH"
      return "INTERVAL_"
          + type.getIntervalQualifier().toString().replace(' ', '_');
    default:
      return type.toString(); // e.g. "VARCHAR(10)", "INTEGER ARRAY"
  }
}
 
Example 7
Source File: PigRelSqlUdfs.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the return data type for a given function.
 *
 * @param function ScalarFunction
 * @return returned data type
 */
private static RelDataType getRelDataType(ScalarFunction function) {
  final JavaTypeFactory typeFactory = TYPE_FACTORY;
  final RelDataType type = function.getReturnType(typeFactory);
  if (type instanceof RelDataTypeFactoryImpl.JavaType
      && ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass()
      == Object.class) {
    return typeFactory.createTypeWithNullability(
        typeFactory.createSqlType(SqlTypeName.ANY), true);
  }
  return typeFactory.toSql(type);
}
 
Example 8
Source File: CalciteCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static RelDataType toSql(RelDataTypeFactory typeFactory,
    RelDataType type) {
  if (type instanceof RelDataTypeFactoryImpl.JavaType
      && ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass()
      == Object.class) {
    return typeFactory.createTypeWithNullability(
        typeFactory.createSqlType(SqlTypeName.ANY), true);
  }
  return JavaTypeFactoryImpl.toSql(typeFactory, type);
}
 
Example 9
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static RelDataType toSql(RelDataTypeFactory typeFactory,
    RelDataType type) {
  if (type instanceof RelDataTypeFactoryImpl.JavaType) {
    final SqlTypeName typeName = type.getSqlTypeName();
    if (typeName != null && typeName != SqlTypeName.OTHER) {
      return typeFactory.createTypeWithNullability(
          typeFactory.createSqlType(typeName),
          type.isNullable());
    }
  }
  return type;
}
 
Example 10
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
private RelDataType nullifyType(JavaTypeFactory typeFactory,
    final RelDataType type, final boolean nullable) {
  if (type instanceof RelDataTypeFactoryImpl.JavaType) {
    final Primitive primitive = Primitive.ofBox(
        ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass());
    if (primitive != null) {
      return typeFactory.createJavaType(primitive.primitiveClass);
    }
  }
  return typeFactory.createTypeWithNullability(type, nullable);
}
 
Example 11
Source File: SqlUserDefinedAggFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
private RelDataType toSql(RelDataType type) {
  if (type instanceof RelDataTypeFactoryImpl.JavaType
      && ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass()
      == Object.class) {
    return typeFactory.createTypeWithNullability(
        typeFactory.createSqlType(SqlTypeName.ANY), true);
  }
  return JavaTypeFactoryImpl.toSql(typeFactory, type);
}
 
Example 12
Source File: PlanExecutor.java    From quark with Apache License 2.0 4 votes vote down vote up
private RelDataTypeFactoryImpl.JavaType getIntegerJavaType() {
  RelDataTypeFactoryImpl relDataTypeFactoryImpl = new JavaTypeFactoryImpl();
  return relDataTypeFactoryImpl.new JavaType(Integer.class);
}
 
Example 13
Source File: PlanExecutor.java    From quark with Apache License 2.0 4 votes vote down vote up
private RelDataTypeFactoryImpl.JavaType getStringJavaType() {
  RelDataTypeFactoryImpl relDataTypeFactoryImpl = new JavaTypeFactoryImpl();
  return relDataTypeFactoryImpl.new JavaType(String.class,
      !(String.class.isPrimitive()), Util.getDefaultCharset(), null);
}