当前位置: 首页>>代码示例>>Java>>正文


Java RelDataTypeFactory.createSqlType方法代码示例

本文整理汇总了Java中org.apache.calcite.rel.type.RelDataTypeFactory.createSqlType方法的典型用法代码示例。如果您正苦于以下问题:Java RelDataTypeFactory.createSqlType方法的具体用法?Java RelDataTypeFactory.createSqlType怎么用?Java RelDataTypeFactory.createSqlType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.rel.type.RelDataTypeFactory的用法示例。


在下文中一共展示了RelDataTypeFactory.createSqlType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCalciteTypeWithNullability

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
private RelDataType createCalciteTypeWithNullability(RelDataTypeFactory typeFactory,
                                                     SqlTypeName sqlTypeName,
                                                     boolean isNullable) {
  RelDataType type;
  if (sqlTypeName == SqlTypeName.INTERVAL_DAY_TIME) {
    type = typeFactory.createSqlIntervalType(
        new SqlIntervalQualifier(
            TimeUnit.DAY,
            TimeUnit.MINUTE,
            SqlParserPos.ZERO));
  } else if (sqlTypeName == SqlTypeName.INTERVAL_YEAR_MONTH) {
    type = typeFactory.createSqlIntervalType(
        new SqlIntervalQualifier(
            TimeUnit.YEAR,
            TimeUnit.MONTH,
           SqlParserPos.ZERO));
  } else if (sqlTypeName == SqlTypeName.VARCHAR) {
    type = typeFactory.createSqlType(sqlTypeName, TypeHelper.VARCHAR_DEFAULT_CAST_LEN);
  } else {
    type = typeFactory.createSqlType(sqlTypeName);
  }
  return typeFactory.createTypeWithNullability(type, isNullable);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:24,代码来源:DrillConstExecutor.java

示例2: convertTypeNotNull

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
private static RelDataType convertTypeNotNull(int type,
    RelDataTypeFactory typeFactory) {

    switch (type) {
        case ColumnTypes.BOOLEAN:
            return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
        case ColumnTypes.INTEGER:
            return typeFactory.createSqlType(SqlTypeName.INTEGER);
        case ColumnTypes.STRING:
            return typeFactory.createSqlType(SqlTypeName.VARCHAR);
        case ColumnTypes.BYTEARRAY:
            return typeFactory.createSqlType(SqlTypeName.VARBINARY);
        case ColumnTypes.LONG:
            return typeFactory.createSqlType(SqlTypeName.BIGINT);
        case ColumnTypes.TIMESTAMP:
            return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
        default:
            return typeFactory.createSqlType(SqlTypeName.ANY);

    }
}
 
开发者ID:diennea,项目名称:herddb,代码行数:22,代码来源:CalcitePlanner.java

示例3: createCalciteTypeWithNullability

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/**
 * Given a {@link SqlTypeName} and nullability, create a RelDataType from the RelDataTypeFactory
 *
 * @param typeFactory RelDataTypeFactory used to create the RelDataType
 * @param sqlTypeName the given SqlTypeName
 * @param isNullable  the nullability of the created RelDataType
 * @return RelDataType Type of call
 */
public static RelDataType createCalciteTypeWithNullability(RelDataTypeFactory typeFactory,
                                                           SqlTypeName sqlTypeName,
                                                           boolean isNullable) {
  RelDataType type;
  if (sqlTypeName == SqlTypeName.INTERVAL_DAY_TIME) {
    type = typeFactory.createSqlIntervalType(
        new SqlIntervalQualifier(
            TimeUnit.DAY,
            TimeUnit.MINUTE,
            SqlParserPos.ZERO));
  } else if (sqlTypeName == SqlTypeName.INTERVAL_YEAR_MONTH) {
    type = typeFactory.createSqlIntervalType(
        new SqlIntervalQualifier(
            TimeUnit.YEAR,
            TimeUnit.MONTH,
            SqlParserPos.ZERO));
  } else if (sqlTypeName == SqlTypeName.VARCHAR) {
    type = typeFactory.createSqlType(sqlTypeName, Types.MAX_VARCHAR_LENGTH);
  } else {
    type = typeFactory.createSqlType(sqlTypeName);
  }
  return typeFactory.createTypeWithNullability(type, isNullable);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:32,代码来源:TypeInferenceUtils.java

示例4: getSqlTypeFromKuduType

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
private RelDataType getSqlTypeFromKuduType(RelDataTypeFactory typeFactory, Type type) {
  switch (type) {
  case BOOL:
    return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
  case DOUBLE:
    return typeFactory.createSqlType(SqlTypeName.DOUBLE);
  case FLOAT:
    return typeFactory.createSqlType(SqlTypeName.FLOAT);
  case INT16:
  case INT32:
  case INT64:
  case INT8:
    return typeFactory.createSqlType(SqlTypeName.INTEGER);
  case STRING:
    return typeFactory.createSqlType(SqlTypeName.VARCHAR);
  case UNIXTIME_MICROS:
    return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
  case BINARY:
    return typeFactory.createSqlType(SqlTypeName.VARBINARY, Integer.MAX_VALUE);
  default:
    throw new UnsupportedOperationException("Unsupported type.");
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:24,代码来源:DrillKuduTable.java

示例5: OctopusTable

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
public OctopusTable(MetaTable metaTable, OctopusSchema schema) {
    super(Object[].class);
    name = metaTable.getName();

    try {
        //tableType = Schema.TableType.valueOf(table.getType().name());
        tableType = Schema.TableType.TABLE; // FIXME
    } catch (IllegalArgumentException e) {
        tableType = Schema.TableType.TABLE;
    }

    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    RelDataTypeFactory.FieldInfoBuilder fieldInfo = typeFactory.builder();
    for (MetaColumn metaColumn : metaTable.getColumns()) {
        String columnName = metaColumn.getName();
        //int jdbcType = metaColumn.getType().getJdbcType();
        int jdbcType = metaColumn.getType(); //FIXME
        SqlTypeName typeName = SqlTypeName.getNameForJdbcType(jdbcType);
        RelDataType sqlType = typeFactory.createSqlType(typeName);

        fieldInfo.add(columnName, sqlType);
    }
    protoRowType = RelDataTypeImpl.proto(fieldInfo.build());

    this.schema = schema;
}
 
开发者ID:bitnine-oss,项目名称:octopus,代码行数:27,代码来源:OctopusTable.java

示例6: SqlValidatorImpl

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/**
 * Creates a validator.
 *
 * @param opTab         Operator table
 * @param catalogReader Catalog reader
 * @param typeFactory   Type factory
 * @param conformance   Compatibility mode
 */
protected SqlValidatorImpl(
    SqlOperatorTable opTab,
    SqlValidatorCatalogReader catalogReader,
    RelDataTypeFactory typeFactory,
    SqlConformance conformance) {
  this.opTab = Preconditions.checkNotNull(opTab);
  this.catalogReader = Preconditions.checkNotNull(catalogReader);
  this.typeFactory = Preconditions.checkNotNull(typeFactory);
  this.conformance = Preconditions.checkNotNull(conformance);

  unknownType = typeFactory.createUnknownType();
  booleanType = typeFactory.createSqlType(SqlTypeName.BOOLEAN);

  rewriteCalls = true;
  expandColumnReferences = true;
  aggFinder = new AggFinder(opTab, false, true, false, null);
  aggOrOverFinder = new AggFinder(opTab, true, true, false, null);
  overFinder = new AggFinder(opTab, true, false, false, aggOrOverFinder);
  groupFinder = new AggFinder(opTab, false, false, true, null);
  aggOrOverOrGroupFinder = new AggFinder(opTab, true, true, true, null);
}
 
开发者ID:apache,项目名称:calcite,代码行数:30,代码来源:SqlValidatorImpl.java

示例7: createSqlType

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
public RelDataType createSqlType(RelDataTypeFactory typeFactory) {
  if (isExact) {
    int scaleValue = scale.intValue();
    if (0 == scaleValue) {
      BigDecimal bd = (BigDecimal) value;
      SqlTypeName result;
      long l = bd.longValue();
      if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) {
        result = SqlTypeName.INTEGER;
      } else {
        result = SqlTypeName.BIGINT;
      }
      return typeFactory.createSqlType(result);
    }

    // else we have a decimal
    return typeFactory.createSqlType(
        SqlTypeName.DECIMAL,
        prec.intValue(),
        scaleValue);
  }

  // else we have a a float, real or double.  make them all double for
  // now.
  return typeFactory.createSqlType(SqlTypeName.DOUBLE);
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:SqlNumericLiteral.java

示例8: testDateLiteral

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/** Tests {@link RexBuilder#makeDateLiteral(DateString)}. */
@Test public void testDateLiteral() {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RelDataType dateType = typeFactory.createSqlType(SqlTypeName.DATE);
  final RexBuilder builder = new RexBuilder(typeFactory);

  // Old way: provide a Calendar
  final Calendar calendar = Util.calendar();
  calendar.set(1969, Calendar.JULY, 21); // one small step
  calendar.set(Calendar.MILLISECOND, 0);
  checkDate(builder.makeLiteral(calendar, dateType, false));

  // Old way #2: Provide in Integer
  checkDate(builder.makeLiteral(MOON_DAY, dateType, false));

  // The new way
  final DateString d = new DateString(1969, 7, 21);
  checkDate(builder.makeLiteral(d, dateType, false));
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:RexBuilderTest.java

示例9: createNlsStringType

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/**
 * Creates the type of an {@link org.apache.calcite.util.NlsString}.
 *
 * <p>The type inherits the The NlsString's {@link Charset} and
 * {@link SqlCollation}, if they are set, otherwise it gets the system
 * defaults.
 *
 * @param typeFactory Type factory
 * @param str         String
 * @return Type, including collation and charset
 */
public static RelDataType createNlsStringType(
    RelDataTypeFactory typeFactory,
    NlsString str) {
  Charset charset = str.getCharset();
  if (null == charset) {
    charset = typeFactory.getDefaultCharset();
  }
  SqlCollation collation = str.getCollation();
  if (null == collation) {
    collation = SqlCollation.COERCIBLE;
  }
  RelDataType type =
      typeFactory.createSqlType(
          SqlTypeName.CHAR,
          str.getValue().length());
  type =
      typeFactory.createTypeWithCharsetAndCollation(
          type,
          charset,
          collation);
  return type;
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:SqlUtil.java

示例10: testProjectPermutation

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
@Test public void testProjectPermutation() {
  final RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl();
  final RexBuilder builder = new RexBuilder(typeFactory);
  final RelDataType doubleType =
      typeFactory.createSqlType(SqlTypeName.DOUBLE);

  // A project with [1, 1] is not a permutation, so should return null
  final Permutation perm = Project.getPermutation(2,
      ImmutableList.of(builder.makeInputRef(doubleType, 1),
          builder.makeInputRef(doubleType, 1)));
  assertThat(perm, nullValue());

  // A project with [0, 1, 0] is not a permutation, so should return null
  final Permutation perm1 = Project.getPermutation(2,
      ImmutableList.of(builder.makeInputRef(doubleType, 0),
          builder.makeInputRef(doubleType, 1),
          builder.makeInputRef(doubleType, 0)));
  assertThat(perm1, nullValue());

  // A project of [1, 0] is a valid permutation!
  final Permutation perm2 = Project.getPermutation(2,
      ImmutableList.of(builder.makeInputRef(doubleType, 1),
          builder.makeInputRef(doubleType, 0)));
  assertThat(perm2, is(new Permutation(new int[]{1, 0})));
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:PermutationTestCase.java

示例11: getRowType

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
public RelDataType getRowType(RelDataTypeFactory factory) {

    // if there are no fields defined, this is a dynamic view.
    if (isDynamic()) {
      return new RelDataTypeDrillImpl(new RelDataTypeHolder(), factory);
    }

    List<RelDataType> types = Lists.newArrayList();
    List<String> names = Lists.newArrayList();

    for (FieldType field : fields) {
      names.add(field.getName());
      RelDataType type;
      if (   SqlTypeFamily.INTERVAL_YEAR_MONTH == field.getType().getFamily()
          || SqlTypeFamily.INTERVAL_DAY_TIME   == field.getType().getFamily() ) {
       type = factory.createSqlIntervalType( field.getIntervalQualifier() );
      } else if (field.getPrecision() == null && field.getScale() == null) {
        type = factory.createSqlType(field.getType());
      } else if (field.getPrecision() != null && field.getScale() == null) {
        type = factory.createSqlType(field.getType(), field.getPrecision());
      } else {
        type = factory.createSqlType(field.getType(), field.getPrecision(), field.getScale());
      }

      if (field.getIsNullable()) {
        types.add(factory.createTypeWithNullability(type, true));
      } else {
        types.add(type);
      }
    }
    return factory.createStructType(types, names);
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:33,代码来源:View.java

示例12: getRelDataType

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
static public RelDataType getRelDataType(RelDataTypeFactory typeFactory, MajorType type) {
  switch (type.getMinorType()) {
  case INT:
    return typeFactory.createSqlType(SqlTypeName.INTEGER);
  case VARCHAR:
    // Note:  Remember to not default to "VARCHAR(1)":
    return typeFactory.createSqlType(SqlTypeName.VARCHAR, Integer.MAX_VALUE);
  default:
    throw new UnsupportedOperationException(
        "Only INT and VARCHAR types are supported in INFORMATION_SCHEMA");
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:13,代码来源:InfoSchemaTable.java

示例13: createNativeScanRel

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
/**
 * Helper method which creates a DrillScalRel with native HiveScan.
 */
private DrillScanRel createNativeScanRel(final Map<String, String> partitionColMapping,
    final DrillScanRel hiveScanRel) throws Exception{

  final RelDataTypeFactory typeFactory = hiveScanRel.getCluster().getTypeFactory();
  final RelDataType varCharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);

  final List<String> nativeScanColNames = Lists.newArrayList();
  final List<RelDataType> nativeScanColTypes = Lists.newArrayList();
  for (RelDataTypeField field : hiveScanRel.getRowType().getFieldList()) {
    final String dirColName = partitionColMapping.get(field.getName());
    if (dirColName != null) { // partition column
      nativeScanColNames.add(dirColName);
      nativeScanColTypes.add(varCharType);
    } else {
      nativeScanColNames.add(field.getName());
      nativeScanColTypes.add(field.getType());
    }
  }

  final RelDataType nativeScanRowType = typeFactory.createStructType(nativeScanColTypes, nativeScanColNames);

  // Create the list of projected columns set in HiveScan. The order of this list may not be same as the order of
  // columns in HiveScan row type. Note: If the HiveScan.getColumn() contains a '*', we just need to add it as it is,
  // unlike above where we expanded the '*'. HiveScan and related (subscan) can handle '*'.
  final List<SchemaPath> nativeScanCols = Lists.newArrayList();
  for(SchemaPath colName : hiveScanRel.getColumns()) {
    final String partitionCol = partitionColMapping.get(colName.getAsUnescapedPath());
    if (partitionCol != null) {
      nativeScanCols.add(SchemaPath.getSimplePath(partitionCol));
    } else {
      nativeScanCols.add(colName);
    }
  }

  final HiveScan hiveScan = (HiveScan) hiveScanRel.getGroupScan();
  final HiveDrillNativeParquetScan nativeHiveScan =
      new HiveDrillNativeParquetScan(
          hiveScan.getUserName(),
          hiveScan.hiveReadEntry,
          hiveScan.storagePlugin,
          nativeScanCols);

  return new DrillScanRel(
      hiveScanRel.getCluster(),
      hiveScanRel.getTraitSet(),
      hiveScanRel.getTable(),
      nativeHiveScan,
      nativeScanRowType,
      nativeScanCols);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:54,代码来源:ConvertHiveParquetScanToDrillParquetScan.java

示例14: getRelDataTypeFromHiveType

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
private RelDataType getRelDataTypeFromHiveType(RelDataTypeFactory typeFactory, TypeInfo typeInfo) {
  switch(typeInfo.getCategory()) {
    case PRIMITIVE:
      return getRelDataTypeFromHivePrimitiveType(typeFactory, ((PrimitiveTypeInfo) typeInfo));

    case LIST: {
      ListTypeInfo listTypeInfo = (ListTypeInfo)typeInfo;
      RelDataType listElemTypeInfo = getRelDataTypeFromHiveType(typeFactory, listTypeInfo.getListElementTypeInfo());
      return typeFactory.createArrayType(listElemTypeInfo, -1);
    }

    case MAP: {
      MapTypeInfo mapTypeInfo = (MapTypeInfo)typeInfo;
      RelDataType keyType = getRelDataTypeFromHiveType(typeFactory, mapTypeInfo.getMapKeyTypeInfo());
      RelDataType valueType = getRelDataTypeFromHiveType(typeFactory, mapTypeInfo.getMapValueTypeInfo());
      return typeFactory.createMapType(keyType, valueType);
    }

    case STRUCT: {
      StructTypeInfo structTypeInfo = (StructTypeInfo)typeInfo;
      ArrayList<String> fieldNames = structTypeInfo.getAllStructFieldNames();
      ArrayList<TypeInfo> fieldHiveTypeInfoList = structTypeInfo.getAllStructFieldTypeInfos();
      List<RelDataType> fieldRelDataTypeList = Lists.newArrayList();
      for(TypeInfo fieldHiveType : fieldHiveTypeInfoList) {
        fieldRelDataTypeList.add(getRelDataTypeFromHiveType(typeFactory, fieldHiveType));
      }
      return typeFactory.createStructType(fieldRelDataTypeList, fieldNames);
    }

    case UNION:
      logger.warn("There is no UNION data type in SQL. Converting it to Sql type OTHER to avoid " +
          "breaking INFORMATION_SCHEMA queries");
      return typeFactory.createSqlType(SqlTypeName.OTHER);
  }

  throwUnsupportedHiveDataTypeError(typeInfo.getCategory().toString());
  return null;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:39,代码来源:DrillHiveTable.java

示例15: getRowType

import org.apache.calcite.rel.type.RelDataTypeFactory; //导入方法依赖的package包/类
public RelDataType getRowType(RelDataTypeFactory factory) {

    List<RelDataType> types = Lists.newArrayList();
    List<String> names = Lists.newArrayList();

    for (FieldType field : fields) {
      names.add(field.getName());
      RelDataType type;
      if (   SqlTypeFamily.INTERVAL_YEAR_MONTH == field.getType().getFamily()
          || SqlTypeFamily.INTERVAL_DAY_TIME   == field.getType().getFamily() ) {
       type = factory.createSqlIntervalType( field.getIntervalQualifier() );
      } else if (field.getType().equals(SqlTypeName.ARRAY) || field.getType().equals(SqlTypeName.MAP)) {
        type = factory.createSqlType(SqlTypeName.ANY);
      } else if (field.getPrecision() == null && field.getScale() == null) {
        type = factory.createSqlType(field.getType());
      } else if (field.getPrecision() != null && field.getScale() == null) {
        type = factory.createSqlType(field.getType(), field.getPrecision());
      } else {
        type = factory.createSqlType(field.getType(), field.getPrecision(), field.getScale());
      }

      if (field.getIsNullable()) {
        types.add(factory.createTypeWithNullability(type, true));
      } else {
        types.add(type);
      }
    }
    return factory.createStructType(types, names);
  }
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:30,代码来源:View.java


注:本文中的org.apache.calcite.rel.type.RelDataTypeFactory.createSqlType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。