• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SqlTypeFactoryImpl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.calcite.sql.type.SqlTypeFactoryImpl的典型用法代码示例。如果您正苦于以下问题:Java SqlTypeFactoryImpl类的具体用法?Java SqlTypeFactoryImpl怎么用?Java SqlTypeFactoryImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SqlTypeFactoryImpl类属于org.apache.calcite.sql.type包,在下文中一共展示了SqlTypeFactoryImpl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getColumnList

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
public List<String> getColumnList(final String username, DatasetPath path) {
  final SchemaConfig schemaConfig = SchemaConfig.newBuilder(username)
      .setProvider(new SchemaInfoProvider() {
        private final ViewExpansionContext viewExpansionContext = new ViewExpansionContext(this, schemaProvider, username);

        @Override
        public ViewExpansionContext getViewExpansionContext() {
          return viewExpansionContext;
        }

        @Override
        public OptionValue getOption(String optionKey) {
          throw new UnsupportedOperationException();
        }
      })
      .build();
  final SchemaPlus schema = schemaProvider.getRootSchema(schemaConfig);
  final Table table = path.getTable(schema);
  return table.getRowType(new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT)).getFieldNames();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:21,代码来源:QueryExecutor.java


示例2: OctopusTable

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的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


示例3: operatorTable

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
/** Creates an operator table that contains functions in the given class.
 *
 * @see ModelHandler#addFunctions */
public static SqlOperatorTable operatorTable(String className) {
  // Dummy schema to collect the functions
  final CalciteSchema schema =
      CalciteSchema.createRootSchema(false, false);
  ModelHandler.addFunctions(schema.plus(), null, ImmutableList.<String>of(),
      className, "*", true);

  // The following is technical debt; see [CALCITE-2082] Remove
  // RelDataTypeFactory argument from SqlUserDefinedAggFunction constructor
  final SqlTypeFactoryImpl typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);

  final ListSqlOperatorTable table = new ListSqlOperatorTable();
  for (String name : schema.getFunctionNames()) {
    for (Function function : schema.getFunctions(name, true)) {
      final SqlIdentifier id = new SqlIdentifier(name, SqlParserPos.ZERO);
      table.add(
          toOp(typeFactory, id, function));
    }
  }
  return table;
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:CalciteCatalogReader.java


示例4: testDateLiteral

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的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


示例5: getRelDataType

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
@Override
RelProtoDataType getRelDataType(
		DatabaseMetaData metaData,
		String catalogName,
		String schemaName,
		String tableName
) throws SQLException {
	if (journalledTableKeys.containsKey(tableName)) {
		// 1: Find columns for journal table
		RelDataType relDataType = super
				.getRelDataType(metaData, catalogName, schemaName, journalNameFor(tableName))
				.apply(new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT) {
					@Override
					public RelDataType copyType(RelDataType type) {
						return type;
					}
				});

		RelDataTypeFactory.FieldInfoBuilder fieldInfo = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT).builder();

		// 2: Filter out journal-implementation columns
		for (RelDataTypeField field : relDataType.getFieldList()) {
			String fieldName = field.getName();
			if (fieldName.equals(versionField) || fieldName.equals(subsequentVersionField)) {
				continue;
			}
			fieldInfo.add(field);
		}

		return RelDataTypeImpl.proto(fieldInfo.build());
	} else {
		return super.getRelDataType(metaData, catalogName, schemaName, tableName);
	}
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:35,代码来源:JournalledJdbcSchema.java


示例6: setup

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);

  final VolcanoPlanner planner = new VolcanoPlanner();
  typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory));
  builder = DremioRelFactories.LOGICAL_BUILDER.create(cluster, schema);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:10,代码来源:TestLayoutExpander.java


示例7: CassandraEnumerator

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
/** Creates a CassandraEnumerator.
 *
 * @param results Cassandra result set ({@link com.datastax.driver.core.ResultSet})
 * @param protoRowType The type of resulting rows
 */
CassandraEnumerator(ResultSet results, RelProtoDataType protoRowType) {
  this.iterator = results.iterator();
  this.current = null;

  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  this.fieldTypes = protoRowType.apply(typeFactory).getFieldList();
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:CassandraEnumerator.java


示例8: getRelDataType

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
RelProtoDataType getRelDataType(DatabaseMetaData metaData, String catalogName,
    String schemaName, String tableName) throws SQLException {
  final ResultSet resultSet =
      metaData.getColumns(catalogName, schemaName, tableName, null);

  // Temporary type factory, just for the duration of this method. Allowable
  // because we're creating a proto-type, not a type; before being used, the
  // proto-type will be copied into a real type factory.
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
  while (resultSet.next()) {
    final String columnName = resultSet.getString(4);
    final int dataType = resultSet.getInt(5);
    final String typeString = resultSet.getString(6);
    final int precision;
    final int scale;
    switch (SqlType.valueOf(dataType)) {
    case TIMESTAMP:
    case TIME:
      precision = resultSet.getInt(9); // SCALE
      scale = 0;
      break;
    default:
      precision = resultSet.getInt(7); // SIZE
      scale = resultSet.getInt(9); // SCALE
      break;
    }
    RelDataType sqlType =
        sqlType(typeFactory, dataType, precision, scale, typeString);
    boolean nullable = resultSet.getInt(11) != DatabaseMetaData.columnNoNulls;
    fieldInfo.add(columnName, sqlType).nullable(nullable);
  }
  resultSet.close();
  return RelDataTypeImpl.proto(fieldInfo.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:37,代码来源:JdbcSchema.java


示例9: getValidator

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
@Override public SqlValidator getValidator(SqlTestFactory factory) {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final SqlConformance conformance = (SqlConformance) get("conformance");
  final boolean caseSensitive = (Boolean) factory.get("caseSensitive");
  return new SqlAdvisorValidator(
      SqlStdOperatorTable.instance(),
      new MockCatalogReader(typeFactory, caseSensitive).init(),
      typeFactory,
      conformance);
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:SqlAdvisorTest.java


示例10: getValidator

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
@Override public SqlValidator getValidator(SqlTestFactory factory) {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  SqlConformance conformance = (SqlConformance) get("conformance");
  final boolean caseSensitive = (Boolean) get("caseSensitive");
  return new FeatureValidator(
      factory.createOperatorTable(factory),
      new MockCatalogReader(typeFactory, caseSensitive).init(),
      typeFactory,
      conformance);
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:SqlValidatorFeatureTest.java


示例11: testArrayAssignment

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1804">[CALCITE-1804]
 * Cannot assign NOT NULL array to nullable array</a>. */
@Test public void testArrayAssignment() {
  final SqlTypeFactoryImpl typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataType bigint = typeFactory.createSqlType(SqlTypeName.BIGINT);
  final RelDataType bigintNullable =
      typeFactory.createTypeWithNullability(bigint, true);
  final RelDataType bigintNotNull =
      typeFactory.createTypeWithNullability(bigint, false);
  final RelDataType date = typeFactory.createSqlType(SqlTypeName.DATE);
  final RelDataType dateNotNull =
      typeFactory.createTypeWithNullability(date, false);
  assertThat(SqlTypeUtil.canAssignFrom(bigintNullable, bigintNotNull),
      is(true));
  assertThat(SqlTypeUtil.canAssignFrom(bigintNullable, dateNotNull),
      is(false));
  final RelDataType bigintNullableArray =
      typeFactory.createArrayType(bigintNullable, -1);
  final RelDataType bigintArrayNullable =
      typeFactory.createTypeWithNullability(bigintNullableArray, true);
  final RelDataType bigintNotNullArray =
      new ArraySqlType(bigintNotNull, false);
  assertThat(SqlTypeUtil.canAssignFrom(bigintArrayNullable, bigintNotNullArray),
      is(true));
  final RelDataType dateNotNullArray =
      new ArraySqlType(dateNotNull, false);
  assertThat(SqlTypeUtil.canAssignFrom(bigintArrayNullable, dateNotNullArray),
      is(false));
}
 
开发者ID:apache,项目名称:calcite,代码行数:32,代码来源:SqlValidatorTest.java


示例12: testTypeDump

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
@Test public void testTypeDump() {
  RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RelDataType t1 =
      typeFactory.builder()
          .add("f0", SqlTypeName.DECIMAL, 5, 2)
          .add("f1", SqlTypeName.VARCHAR, 10)
          .build();
  TestUtil.assertEqualsVerbose(
      TestUtil.fold(
          "f0 DECIMAL(5, 2) NOT NULL,",
          "f1 VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL"),
      Util.toLinux(RelOptUtil.dumpType(t1) + "\n"));

  RelDataType t2 =
      typeFactory.builder()
          .add("f0", t1)
          .add("f1", typeFactory.createMultisetType(t1, -1))
          .build();
  TestUtil.assertEqualsVerbose(
      TestUtil.fold(
          "f0 RECORD (",
          "  f0 DECIMAL(5, 2) NOT NULL,",
          "  f1 VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL) NOT NULL,",
          "f1 RECORD (",
          "  f0 DECIMAL(5, 2) NOT NULL,",
          "  f1 VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL) NOT NULL MULTISET NOT NULL"),
      Util.toLinux(RelOptUtil.dumpType(t2) + "\n"));
}
 
开发者ID:apache,项目名称:calcite,代码行数:30,代码来源:RelOptUtilTest.java


示例13: testEnsureTypeWithAny

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
/**
 * Test RexBuilder.ensureType()
 */
@Test
public void testEnsureTypeWithAny() {
  final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RexBuilder builder = new RexBuilder(typeFactory);

  RexNode node =  new RexLiteral(
          Boolean.TRUE, typeFactory.createSqlType(SqlTypeName.BOOLEAN), SqlTypeName.BOOLEAN);
  RexNode ensuredNode = builder.ensureType(
          typeFactory.createSqlType(SqlTypeName.ANY), node, true);

  assertEquals(node, ensuredNode);
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:RexBuilderTest.java


示例14: testEnsureTypeWithItself

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
/**
 * Test RexBuilder.ensureType()
 */
@Test
public void testEnsureTypeWithItself() {
  final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RexBuilder builder = new RexBuilder(typeFactory);

  RexNode node =  new RexLiteral(
          Boolean.TRUE, typeFactory.createSqlType(SqlTypeName.BOOLEAN), SqlTypeName.BOOLEAN);
  RexNode ensuredNode = builder.ensureType(
          typeFactory.createSqlType(SqlTypeName.BOOLEAN), node, true);

  assertEquals(node, ensuredNode);
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:RexBuilderTest.java


示例15: testEnsureTypeWithDifference

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
/**
 * Test RexBuilder.ensureType()
 */
@Test
public void testEnsureTypeWithDifference() {
  final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RexBuilder builder = new RexBuilder(typeFactory);

  RexNode node =  new RexLiteral(
          Boolean.TRUE, typeFactory.createSqlType(SqlTypeName.BOOLEAN), SqlTypeName.BOOLEAN);
  RexNode ensuredNode = builder.ensureType(
          typeFactory.createSqlType(SqlTypeName.INTEGER), node, true);

  assertNotEquals(node, ensuredNode);
  assertEquals(ensuredNode.getType(), typeFactory.createSqlType(SqlTypeName.INTEGER));
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RexBuilderTest.java


示例16: getRelDataType

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
RelProtoDataType getRelDataType(String columnFamily, boolean view) {
  List<ColumnMetadata> columns;
  if (view) {
    columns = getKeyspace().getMaterializedView(columnFamily).getColumns();
  } else {
    columns = getKeyspace().getTable(columnFamily).getColumns();
  }

  // Temporary type factory, just for the duration of this method. Allowable
  // because we're creating a proto-type, not a type; before being used, the
  // proto-type will be copied into a real type factory.
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
  for (ColumnMetadata column : columns) {
    final String columnName = column.getName();
    final DataType type = column.getType();

    // TODO: This mapping of types can be done much better
    SqlTypeName typeName = SqlTypeName.ANY;
    if (type == DataType.uuid() || type == DataType.timeuuid()) {
      // We currently rely on this in CassandraFilter to detect UUID columns.
      // That is, these fixed length literals should be unquoted in CQL.
      typeName = SqlTypeName.CHAR;
    } else if (type == DataType.ascii() || type == DataType.text()
          || type == DataType.varchar()) {
      typeName = SqlTypeName.VARCHAR;
    } else if (type == DataType.cint() || type == DataType.varint()) {
      typeName = SqlTypeName.INTEGER;
    } else if (type == DataType.bigint()) {
      typeName = SqlTypeName.BIGINT;
    } else if (type == DataType.cdouble() || type == DataType.cfloat()
        || type == DataType.decimal()) {
      typeName = SqlTypeName.DOUBLE;
    }

    fieldInfo.add(columnName, typeFactory.createSqlType(typeName)).nullable(true);
  }

  return RelDataTypeImpl.proto(fieldInfo.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:42,代码来源:CassandraSchema.java


示例17: createTypeFactory

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
protected RelDataTypeFactory createTypeFactory() {
  return new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
}
 
开发者ID:apache,项目名称:calcite,代码行数:4,代码来源:SqlToRelTestBase.java


示例18: newCluster

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
static RelOptCluster newCluster(VolcanoPlanner planner) {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(org.apache.calcite.rel.type.RelDataTypeSystem.DEFAULT);
  return RelOptCluster.create(planner, new RexBuilder(typeFactory));
}
 
开发者ID:apache,项目名称:calcite,代码行数:6,代码来源:PlannerTests.java


示例19: testTimestampLiteral

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
/** Tests {@link RexBuilder#makeTimestampLiteral(TimestampString, int)}. */
@Test public void testTimestampLiteral() {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataType timestampType =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
  final RelDataType timestampType3 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 3);
  final RelDataType timestampType9 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9);
  final RelDataType timestampType18 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 18);
  final RexBuilder builder = new RexBuilder(typeFactory);

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

  // Old way #2: Provide a Long
  checkTimestamp(builder.makeLiteral(MOON, timestampType, false));

  // The new way
  final TimestampString ts = new TimestampString(1969, 7, 21, 2, 56, 15);
  checkTimestamp(builder.makeLiteral(ts, timestampType, false));

  // Now with milliseconds
  final TimestampString ts2 = ts.withMillis(56);
  assertThat(ts2.toString(), is("1969-07-21 02:56:15.056"));
  final RexNode literal2 = builder.makeLiteral(ts2, timestampType3, false);
  assertThat(((RexLiteral) literal2).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15.056"));

  // Now with nanoseconds
  final TimestampString ts3 = ts.withNanos(56);
  final RexNode literal3 = builder.makeLiteral(ts3, timestampType9, false);
  assertThat(((RexLiteral) literal3).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15"));
  final TimestampString ts3b = ts.withNanos(2345678);
  final RexNode literal3b = builder.makeLiteral(ts3b, timestampType9, false);
  assertThat(((RexLiteral) literal3b).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15.002"));

  // Now with a very long fraction
  final TimestampString ts4 = ts.withFraction("102030405060708090102");
  final RexNode literal4 = builder.makeLiteral(ts4, timestampType18, false);
  assertThat(((RexLiteral) literal4).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15.102"));

  // toString
  assertThat(ts2.round(1).toString(), is("1969-07-21 02:56:15"));
  assertThat(ts2.round(2).toString(), is("1969-07-21 02:56:15.05"));
  assertThat(ts2.round(3).toString(), is("1969-07-21 02:56:15.056"));
  assertThat(ts2.round(4).toString(), is("1969-07-21 02:56:15.056"));

  assertThat(ts2.toString(6), is("1969-07-21 02:56:15.056000"));
  assertThat(ts2.toString(1), is("1969-07-21 02:56:15.0"));
  assertThat(ts2.toString(0), is("1969-07-21 02:56:15"));

  assertThat(ts2.round(0).toString(), is("1969-07-21 02:56:15"));
  assertThat(ts2.round(0).toString(0), is("1969-07-21 02:56:15"));
  assertThat(ts2.round(0).toString(1), is("1969-07-21 02:56:15.0"));
  assertThat(ts2.round(0).toString(2), is("1969-07-21 02:56:15.00"));

  assertThat(TimestampString.fromMillisSinceEpoch(1456513560123L).toString(),
      is("2016-02-26 19:06:00.123"));
}
 
开发者ID:apache,项目名称:calcite,代码行数:69,代码来源:RexBuilderTest.java


示例20: testTimestampWithLocalTimeZoneLiteral

import org.apache.calcite.sql.type.SqlTypeFactoryImpl; //导入依赖的package包/类
/** Tests
 * {@link RexBuilder#makeTimestampWithLocalTimeZoneLiteral(TimestampString, int)}. */
@Test public void testTimestampWithLocalTimeZoneLiteral() {
  final RelDataTypeFactory typeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RelDataType timestampType =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE);
  final RelDataType timestampType3 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE, 3);
  final RelDataType timestampType9 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE, 9);
  final RelDataType timestampType18 =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE, 18);
  final RexBuilder builder = new RexBuilder(typeFactory);

  // The new way
  final TimestampWithTimeZoneString ts = new TimestampWithTimeZoneString(
      1969, 7, 21, 2, 56, 15, TimeZone.getTimeZone("PST").getID());
  checkTimestampWithLocalTimeZone(
      builder.makeLiteral(ts.getLocalTimestampString(), timestampType, false));

  // Now with milliseconds
  final TimestampWithTimeZoneString ts2 = ts.withMillis(56);
  assertThat(ts2.toString(), is("1969-07-21 02:56:15.056 PST"));
  final RexNode literal2 = builder.makeLiteral(
      ts2.getLocalTimestampString(), timestampType3, false);
  assertThat(((RexLiteral) literal2).getValue().toString(), is("1969-07-21 02:56:15.056"));

  // Now with nanoseconds
  final TimestampWithTimeZoneString ts3 = ts.withNanos(56);
  final RexNode literal3 = builder.makeLiteral(
      ts3.getLocalTimestampString(), timestampType9, false);
  assertThat(((RexLiteral) literal3).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15"));
  final TimestampWithTimeZoneString ts3b = ts.withNanos(2345678);
  final RexNode literal3b = builder.makeLiteral(
      ts3b.getLocalTimestampString(), timestampType9, false);
  assertThat(((RexLiteral) literal3b).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15.002"));

  // Now with a very long fraction
  final TimestampWithTimeZoneString ts4 = ts.withFraction("102030405060708090102");
  final RexNode literal4 = builder.makeLiteral(
      ts4.getLocalTimestampString(), timestampType18, false);
  assertThat(((RexLiteral) literal4).getValueAs(TimestampString.class)
          .toString(), is("1969-07-21 02:56:15.102"));

  // toString
  assertThat(ts2.round(1).toString(), is("1969-07-21 02:56:15 PST"));
  assertThat(ts2.round(2).toString(), is("1969-07-21 02:56:15.05 PST"));
  assertThat(ts2.round(3).toString(), is("1969-07-21 02:56:15.056 PST"));
  assertThat(ts2.round(4).toString(), is("1969-07-21 02:56:15.056 PST"));

  assertThat(ts2.toString(6), is("1969-07-21 02:56:15.056000 PST"));
  assertThat(ts2.toString(1), is("1969-07-21 02:56:15.0 PST"));
  assertThat(ts2.toString(0), is("1969-07-21 02:56:15 PST"));

  assertThat(ts2.round(0).toString(), is("1969-07-21 02:56:15 PST"));
  assertThat(ts2.round(0).toString(0), is("1969-07-21 02:56:15 PST"));
  assertThat(ts2.round(0).toString(1), is("1969-07-21 02:56:15.0 PST"));
  assertThat(ts2.round(0).toString(2), is("1969-07-21 02:56:15.00 PST"));
}
 
开发者ID:apache,项目名称:calcite,代码行数:63,代码来源:RexBuilderTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DOMHelper类代码示例发布时间:2022-05-23
下一篇:
Java DocIdPusher类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap