org.apache.calcite.sql.type.SqlTypeName Java Examples

The following examples show how to use org.apache.calcite.sql.type.SqlTypeName. 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: UnnestPrel.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
public Prel prepareForLateralUnnestPipeline(List<RelNode> children) {
  RelDataTypeFactory typeFactory = this.getCluster().getTypeFactory();
  List<String> fieldNames = new ArrayList<>();
  List<RelDataType> fieldTypes = new ArrayList<>();

  fieldNames.add(IMPLICIT_COLUMN);
  fieldTypes.add(typeFactory.createSqlType(SqlTypeName.INTEGER));

  for (RelDataTypeField field : this.rowType.getFieldList()) {
    fieldNames.add(field.getName());
    fieldTypes.add(field.getType());
  }

  RelDataType newRowType = typeFactory.createStructType(fieldTypes, fieldNames);
  return new UnnestPrel(this.getCluster(), this.getTraitSet(), newRowType, ref);
}
 
Example #2
Source File: SqlTumbleTableFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  // There should only be three operands, and number of operands are checked before
  // this call.
  final SqlNode operand0 = callBinding.operand(0);
  final SqlValidator validator = callBinding.getValidator();
  final RelDataType type = validator.getValidatedNodeType(operand0);
  if (type.getSqlTypeName() != SqlTypeName.ROW) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  final SqlNode operand1 = callBinding.operand(1);
  if (operand1.getKind() != SqlKind.DESCRIPTOR) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  validateColumnNames(validator, type.getFieldNames(), ((SqlCall) operand1).getOperandList());
  final RelDataType type2 = validator.getValidatedNodeType(callBinding.operand(2));
  if (!SqlTypeUtil.isInterval(type2)) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  return true;
}
 
Example #3
Source File: RexProgramTestBase.java    From calcite with Apache License 2.0 6 votes vote down vote up
protected void checkSimplify3_(RexNode node, String expected,
                             String expectedFalse, String expectedTrue) {
  final RexNode simplified =
      simplify.simplifyUnknownAs(node, RexUnknownAs.UNKNOWN);
  assertThat("simplify(unknown as unknown): " + node,
      simplified.toString(), equalTo(expected));
  if (node.getType().getSqlTypeName() == SqlTypeName.BOOLEAN) {
    final RexNode simplified2 =
        simplify.simplifyUnknownAs(node, RexUnknownAs.FALSE);
    assertThat("simplify(unknown as false): " + node,
        simplified2.toString(), equalTo(expectedFalse));
    final RexNode simplified3 =
        simplify.simplifyUnknownAs(node, RexUnknownAs.TRUE);
    assertThat("simplify(unknown as true): " + node,
        simplified3.toString(), equalTo(expectedTrue));
  } else {
    assertThat("node type is not BOOLEAN, so <<expectedFalse>> should match <<expected>>",
        expectedFalse, is(expected));
    assertThat("node type is not BOOLEAN, so <<expectedTrue>> should match <<expected>>",
        expectedTrue, is(expected));
  }
}
 
Example #4
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = Objects.requireNonNull(opTab);
	this.catalogReader = Objects.requireNonNull(catalogReader);
	this.typeFactory = Objects.requireNonNull(typeFactory);
	this.conformance = Objects.requireNonNull(conformance);

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

	rewriteCalls = true;
	expandColumnReferences = true;
	final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
	aggFinder = new AggFinder(opTab, false, true, false, null, nameMatcher);
	aggOrOverFinder = new AggFinder(opTab, true, true, false, null, nameMatcher);
	overFinder = new AggFinder(opTab, true, false, false, aggOrOverFinder, nameMatcher);
	groupFinder = new AggFinder(opTab, false, false, true, null, nameMatcher);
	aggOrOverOrGroupFinder = new AggFinder(opTab, true, true, true, null, nameMatcher);
}
 
Example #5
Source File: FlattenConvertlet.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
  SqlFlattenOperator operator = (SqlFlattenOperator) call.getOperator();
  final List<RexNode> exprs = new LinkedList<>();

  for (SqlNode node : call.getOperandList()) {
    exprs.add(cx.convertExpression(node));
  }

  SqlFlattenOperator indexedOperator = operator.withIndex(((SqlValidatorImpl)cx.getValidator()).nextFlattenIndex());
  final RexBuilder rexBuilder = cx.getRexBuilder();
  // Since we don't have any way of knowing if the output of the flatten is nullable, we should always assume it is.
  // This is especially important when accelerating a count(column) query, because the normalizer will convert it to
  // a count(1) if it thinks this column is non-nullable, and then remove the flatten altogether. This is actually a
  // problem with the fact that flatten is not really a project operator (because it can output more than one row per input).
  RelDataType type = rexBuilder
    .getTypeFactory()
    .createTypeWithNullability(
      rexBuilder
        .getTypeFactory()
        .createSqlType(SqlTypeName.ANY),
      true
    );
  return rexBuilder.makeCall(type, indexedOperator, exprs);

}
 
Example #6
Source File: RelToSqlConverterStructsTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Table schema is as following:
 *  myTable(
 *          a: BIGINT,
 *          n1: STRUCT<
 *                n11: STRUCT<b: BIGINT>,
 *                n12: STRUCT<c: BIGINT>
 *              >,
 *          n2: STRUCT<d: BIGINT>,
 *          e: BIGINT
 *  )
 */
@Override public RelDataType getRowType(RelDataTypeFactory tf) {
  RelDataType bigint = tf.createSqlType(SqlTypeName.BIGINT);
  RelDataType n1Type = tf.createStructType(
      ImmutableList.of(
          tf.createStructType(ImmutableList.of(bigint),
              ImmutableList.of("b")),
          tf.createStructType(ImmutableList.of(bigint),
              ImmutableList.of("c"))),
      ImmutableList.of("n11", "n12"));
  RelDataType n2Type = tf.createStructType(
      ImmutableList.of(bigint),
      ImmutableList.of("d"));
  return tf.createStructType(
      ImmutableList.of(bigint, n1Type, n2Type, bigint),
      ImmutableList.of("a", "n1", "n2", "e"));
}
 
Example #7
Source File: FlinkReturnTypes.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
	RelDataType type = super.inferReturnType(opBinding);
	RelDataType newType;
	switch (type.getSqlTypeName()) {
		case CHAR:
			newType = opBinding.getTypeFactory().createSqlType(SqlTypeName.VARCHAR, type.getPrecision());
			break;
		case VARCHAR:
			newType = type;
			break;
		default:
			throw new UnsupportedOperationException("Unsupported type: " + type);
	}
	return opBinding.getTypeFactory().createTypeWithNullability(newType, true);
}
 
Example #8
Source File: TypeInferenceUtils.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * 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.getFamily() == SqlTypeFamily.INTERVAL_DAY_TIME) {
    type = typeFactory.createSqlIntervalType(
        new SqlIntervalQualifier(
            TimeUnit.DAY,
            TimeUnit.MINUTE,
            SqlParserPos.ZERO));
  } else if (sqlTypeName.getFamily() == SqlTypeFamily.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);
}
 
Example #9
Source File: RelDataTypeSystemImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
public int getMaxScale(SqlTypeName typeName) {
  switch (typeName) {
  case DECIMAL:
    return getMaxNumericScale();
  case INTERVAL_YEAR:
  case INTERVAL_YEAR_MONTH:
  case INTERVAL_MONTH:
  case INTERVAL_DAY:
  case INTERVAL_DAY_HOUR:
  case INTERVAL_DAY_MINUTE:
  case INTERVAL_DAY_SECOND:
  case INTERVAL_HOUR:
  case INTERVAL_HOUR_MINUTE:
  case INTERVAL_HOUR_SECOND:
  case INTERVAL_MINUTE:
  case INTERVAL_MINUTE_SECOND:
  case INTERVAL_SECOND:
    return SqlTypeName.MAX_INTERVAL_FRACTIONAL_SECOND_PRECISION;
  default:
    return -1;
  }
}
 
Example #10
Source File: RexProgramTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testSimplifyCastLiteral2() {
  final RexLiteral literalAbc = rexBuilder.makeLiteral("abc");
  final RexLiteral literalOne = rexBuilder.makeExactLiteral(BigDecimal.ONE);
  final RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);
  final RelDataType varcharType =
      typeFactory.createSqlType(SqlTypeName.VARCHAR, 10);
  final RelDataType booleanType =
      typeFactory.createSqlType(SqlTypeName.BOOLEAN);
  final RelDataType dateType = typeFactory.createSqlType(SqlTypeName.DATE);
  final RelDataType timestampType =
      typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
  checkSimplifyUnchanged(cast(literalAbc, intType));
  checkSimplifyUnchanged(cast(literalOne, intType));
  checkSimplifyUnchanged(cast(literalAbc, varcharType));
  checkSimplify(cast(literalOne, varcharType), "'1':VARCHAR(10)");
  checkSimplifyUnchanged(cast(literalAbc, booleanType));
  checkSimplify(cast(literalOne, booleanType),
      "false"); // different from Hive
  checkSimplifyUnchanged(cast(literalAbc, dateType));
  checkSimplify(cast(literalOne, dateType),
      "1970-01-02"); // different from Hive
  checkSimplifyUnchanged(cast(literalAbc, timestampType));
  checkSimplify(cast(literalOne, timestampType),
      "1970-01-01 00:00:00"); // different from Hive
}
 
Example #11
Source File: JSqlMapData.java    From kafka-eagle with Apache License 2.0 6 votes vote down vote up
private static void loadDatabaseType() {
	SQLTYPE_MAPPING.put("char", SqlTypeName.CHAR);
	JAVATYPE_MAPPING.put("char", Character.class);
	SQLTYPE_MAPPING.put("varchar", SqlTypeName.VARCHAR);
	JAVATYPE_MAPPING.put("varchar", String.class);
	SQLTYPE_MAPPING.put("boolean", SqlTypeName.BOOLEAN);
	SQLTYPE_MAPPING.put("integer", SqlTypeName.INTEGER);
	JAVATYPE_MAPPING.put("integer", Integer.class);
	SQLTYPE_MAPPING.put("tinyint", SqlTypeName.TINYINT);
	SQLTYPE_MAPPING.put("smallint", SqlTypeName.SMALLINT);
	SQLTYPE_MAPPING.put("bigint", SqlTypeName.BIGINT);
	JAVATYPE_MAPPING.put("bigint", Long.class);
	SQLTYPE_MAPPING.put("decimal", SqlTypeName.DECIMAL);
	SQLTYPE_MAPPING.put("numeric", SqlTypeName.DECIMAL);
	SQLTYPE_MAPPING.put("float", SqlTypeName.FLOAT);
	SQLTYPE_MAPPING.put("real", SqlTypeName.REAL);
	SQLTYPE_MAPPING.put("double", SqlTypeName.DOUBLE);
	SQLTYPE_MAPPING.put("date", SqlTypeName.DATE);
	JAVATYPE_MAPPING.put("date", Date.class);
	SQLTYPE_MAPPING.put("time", SqlTypeName.TIME);
	SQLTYPE_MAPPING.put("timestamp", SqlTypeName.TIMESTAMP);
	SQLTYPE_MAPPING.put("any", SqlTypeName.ANY);
}
 
Example #12
Source File: PreferredAlbumsTableFactory.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public AbstractQueryableTable create(
    SchemaPlus schema,
    String name,
    Map<String, Object> operand,
    RelDataType rowType) {
  return new AbstractQueryableTable(Integer.class) {
    @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
      return typeFactory.builder().add("ID", SqlTypeName.INTEGER).build();
    }

    @Override public Queryable<Integer> asQueryable(
        QueryProvider qp,
        SchemaPlus sp,
        String string) {
      return fetchPreferredAlbums();
    }
  };
}
 
Example #13
Source File: RexBuilderTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Tests {@link RexCopier#visitRangeRef(RexRangeRef)} */
@Test void testCopyRangeRef() {
  final RelDataTypeFactory sourceTypeFactory =
      new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  RelDataType type = sourceTypeFactory.createSqlType(SqlTypeName.VARCHAR, 65536);

  final RelDataTypeFactory targetTypeFactory =
      new MySqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
  final RexBuilder builder = new RexBuilder(targetTypeFactory);

  final RexRangeRef node = builder.makeRangeReference(type, 1, true);
  final RexNode copy = builder.copy(node);
  assertTrue(copy instanceof RexRangeRef);

  final RexRangeRef result = (RexRangeRef) copy;
  assertThat(result.getOffset(), is(node.getOffset()));
  assertThat(result.getType().getSqlTypeName(), is(SqlTypeName.VARCHAR));
  assertThat(result.getType().getPrecision(), is(PRECISION));
}
 
Example #14
Source File: JoinRelBase.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override public boolean isValid(Litmus litmus, Context context) {
  if (condition != null) {
    if (condition.getType().getSqlTypeName() != SqlTypeName.BOOLEAN) {
      return litmus.fail("condition must be boolean: {}",
        condition.getType());
    }
    // The input to the condition is a row type consisting of system
    // fields, left fields, and right fields. Very similar to the
    // output row type, except that fields have not yet been made due
    // due to outer joins.
    RexChecker checker =
      new RexChecker(
        getCluster().getTypeFactory().builder()
          .addAll(getSystemFieldList())
          .addAll(getLeft().getRowType().getFieldList())
          .addAll(getRight().getRowType().getFieldList())
          .build(),
        context, litmus);
    condition.accept(checker);
    if (checker.getFailureCount() > 0) {
      return litmus.fail(checker.getFailureCount()
        + " failures in condition " + condition);
    }
  }
  return litmus.succeed();
}
 
Example #15
Source File: TestSQLAnalyzer.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Prepare.PreparingTable getTable(List<String> names) {
  // Create table used for suggestion
  if (names.contains("TEST_TABLE")) {
    MockTable mockTable = new MockTable("TEST_TABLE", this);
    mockTable.addColumn("colOne", typeFactory.createSqlType(SqlTypeName.INTEGER));
    mockTable.addColumn("colTwo", typeFactory.createSqlType(SqlTypeName.INTEGER));
    return mockTable;
  }

  return null;
}
 
Example #16
Source File: JdbcToEnumerableConverter.java    From calcite with Apache License 2.0 5 votes vote down vote up
private Method getMethod2(SqlTypeName sqlTypeName) {
  switch (sqlTypeName) {
  case DATE:
    return BuiltInMethod.RESULT_SET_GET_DATE2.method;
  case TIME:
    return BuiltInMethod.RESULT_SET_GET_TIME2.method;
  case TIMESTAMP:
    return BuiltInMethod.RESULT_SET_GET_TIMESTAMP2.method;
  default:
    throw new AssertionError(sqlTypeName);
  }
}
 
Example #17
Source File: OracleSqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public int getMaxPrecision(SqlTypeName typeName) {
  switch (typeName) {
  case VARCHAR:
    // Maximum size of 4000 bytes for varchar2.
    return 4000;
  default:
    return super.getMaxPrecision(typeName);
  }
}
 
Example #18
Source File: DremioArgChecker.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static Checker ofDouble(String argName) {
  return new Checker() {

    @Override
    public boolean check(RelDataType type) {
      return type.getSqlTypeName() == SqlTypeName.DOUBLE;
    }

    @Override
    public String signature() {
      return argName + " <DOUBLE>";
    }

  };
}
 
Example #19
Source File: CalciteArrowHelper.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public RelDataType toCalciteType(RelDataTypeFactory typeFactory) {
      final MinorType type = completeType.toMinorType();
      if (completeType.isList()) {
//        RelDataType childType = convertFieldToRelDataType(field.getChildren().iterator().next(), typeFactory);
//        return typeFactory.createArrayType(childType, -1);
        return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.ANY), true);
      }
      if (completeType.isStruct()) {
//        return convertFieldsToStruct(field.getChildren(), typeFactory);
        return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.ANY), true);
      }

      final SqlTypeName sqlTypeName = getCalciteTypeFromMinorType(type);

      if(completeType.isVariableWidthScalar()){
        return typeFactory.createTypeWithNullability(typeFactory.createSqlType(sqlTypeName, 1 << 16), true);
      }

      if(completeType.isDecimal()){
        return typeFactory.createTypeWithNullability(typeFactory.createSqlType(sqlTypeName, completeType.getPrecision(), completeType.getScale()), true);
      }

      if (completeType.getType().getTypeID() == ArrowTypeID.Timestamp ||
          completeType.getType().getTypeID() == ArrowTypeID.Time) {
        return typeFactory.createTypeWithNullability(typeFactory.createSqlType(sqlTypeName, completeType.getPrecision()), true);
      }

      return typeFactory.createTypeWithNullability(typeFactory.createSqlType(sqlTypeName), true);
    }
 
Example #20
Source File: SqlNumericLiteral.java    From calcite with Apache License 2.0 5 votes vote down vote up
protected SqlNumericLiteral(
    BigDecimal value,
    Integer prec,
    Integer scale,
    boolean isExact,
    SqlParserPos pos) {
  super(
      value,
      isExact ? SqlTypeName.DECIMAL : SqlTypeName.DOUBLE,
      pos);
  this.prec = prec;
  this.scale = scale;
  this.isExact = isExact;
}
 
Example #21
Source File: JethroDataSqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
JethroSupportedFunction(String name, String operands) {
  Objects.requireNonNull(name); // not currently used
  final ImmutableList.Builder<SqlTypeName> b = ImmutableList.builder();
  for (String strType : operands.split(":")) {
    b.add(parse(strType));
  }
  this.operandTypes = b.build();
}
 
Example #22
Source File: ClickHouseSqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
private SqlDataTypeSpec createSqlDataTypeSpecByName(String typeAlias, SqlTypeName typeName) {
  SqlBasicTypeNameSpec spec = new SqlBasicTypeNameSpec(typeName, SqlParserPos.ZERO) {
    @Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
      // unparse as an identifier to ensure that type names are cased correctly
      writer.identifier(typeAlias, true);
    }
  };
  return new SqlDataTypeSpec(spec, SqlParserPos.ZERO);
}
 
Example #23
Source File: SamzaSqlValidator.java    From samza with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example #24
Source File: TypeInferenceUtils.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory factory = opBinding.getTypeFactory();
  final SqlTypeName type = SqlTypeName.VARBINARY;

  return createCalciteTypeWithNullability(factory, type, opBinding.getOperandType(0).isNullable(), null);
}
 
Example #25
Source File: RelBuilderTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
private RexNode over(RelBuilder b,
    ImmutableList<RexFieldCollation> fieldCollations, String alias) {
  final RelDataType intType =
      b.getTypeFactory().createSqlType(SqlTypeName.INTEGER);
  return b.alias(
      b.getRexBuilder()
          .makeOver(intType, SqlStdOperatorTable.ROW_NUMBER,
              ImmutableList.of(), ImmutableList.of(), fieldCollations,
              RexWindowBounds.UNBOUNDED_PRECEDING,
              RexWindowBounds.UNBOUNDED_FOLLOWING, true, true, false,
              false, false), alias);
}
 
Example #26
Source File: View.java    From Bats with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public Field(
    @JsonProperty("name")                       String name,
    @JsonProperty("type")                       SqlTypeName type,
    @JsonProperty("precision")                  Integer precision,
    @JsonProperty("scale")                      Integer scale,
    @JsonProperty("startUnit")                  TimeUnit startUnit,
    @JsonProperty("endUnit")                    TimeUnit endUnit,
    @JsonProperty("fractionalSecondPrecision")  Integer fractionalSecondPrecision,
    @JsonProperty("isNullable")                 Boolean isNullable,
    @JsonProperty("keyType") Field keyType,
    @JsonProperty("valueType") Field valueType) {
  // Fix for views which were created on Calcite 1.4.
  // After Calcite upgrade star "*" was changed on dynamic star "**" (SchemaPath.DYNAMIC_STAR)
  // and type of star was changed to SqlTypeName.DYNAMIC_STAR
  this.name = "*".equals(name) ? SchemaPath.DYNAMIC_STAR : name;
  this.type = "*".equals(name) && type == SqlTypeName.ANY ? SqlTypeName.DYNAMIC_STAR : type;
  this.precision = precision;
  this.scale = scale;
  this.intervalQualifier =
      null == startUnit
      ? null
      : new SqlIntervalQualifier(
          startUnit, precision, endUnit, fractionalSecondPrecision, SqlParserPos.ZERO );

  // Property "isNullable" is not part of the initial view definition and
  // was added in DRILL-2342.  If the default value is null, consider it as
  // "true".  It is safe to default to "nullable" than "required" type.
  this.isNullable = isNullable == null || isNullable;
  this.keyType = keyType;
  this.valueType = valueType;
}
 
Example #27
Source File: JoinTranslator.java    From samza with Apache License 2.0 5 votes vote down vote up
private void validateJoinKeyType(RexInputRef ref) {
  SqlTypeName sqlTypeName = ref.getType().getSqlTypeName();

  // Primitive types and ANY (for the record key) are supported in the key
  if (sqlTypeName != SqlTypeName.BOOLEAN && sqlTypeName != SqlTypeName.TINYINT && sqlTypeName != SqlTypeName.SMALLINT
      && sqlTypeName != SqlTypeName.INTEGER && sqlTypeName != SqlTypeName.CHAR && sqlTypeName != SqlTypeName.BIGINT
      && sqlTypeName != SqlTypeName.VARCHAR && sqlTypeName != SqlTypeName.DOUBLE && sqlTypeName != SqlTypeName.FLOAT
      && sqlTypeName != SqlTypeName.ANY && sqlTypeName != SqlTypeName.OTHER) {
    log.error("Unsupported key type " + sqlTypeName + " used in join condition.");
    throw new SamzaException("Unsupported key type used in join condition.");
  }
}
 
Example #28
Source File: RexProgramTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Unit test for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1289">[CALCITE-1289]
 * RexUtil.simplifyCase() should account for nullability</a>. */
@Test void testSimplifyCaseNotNullableBoolean() {
  RexNode condition = eq(vVarchar(), literal("S"));
  RexCall caseNode = (RexCall) case_(condition, trueLiteral, falseLiteral);

  final RexCall result = (RexCall) simplify.simplifyUnknownAs(caseNode, RexUnknownAs.UNKNOWN);
  assertThat("The case should be nonNullable", caseNode.getType().isNullable(), is(false));
  assertThat("Expected a nonNullable type", result.getType().isNullable(), is(false));
  assertThat(result.getType().getSqlTypeName(), is(SqlTypeName.BOOLEAN));
  assertThat(result.getOperator(), is((SqlOperator) SqlStdOperatorTable.IS_TRUE));
  assertThat(result.getOperands().get(0), is(condition));
}
 
Example #29
Source File: SqlTimestampType.java    From flink with Apache License 2.0 5 votes vote down vote up
private static String getTypeName(boolean withLocalTimeZone) {
	if (withLocalTimeZone) {
		return SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE.name();
	} else {
		return SqlTypeName.TIMESTAMP.name();
	}
}
 
Example #30
Source File: TypeInferenceUtil.java    From marble with Apache License 2.0 5 votes vote down vote up
private static ObjectInspector getPrimitiveObjectInspector(
    RelDataTypeHolder relDataTypeHolder) {
  SqlTypeName sqlTypeName = relDataTypeHolder.getSqlTypeName();

  //FIXME Hive TypeInfoFactory.decimalTypeInfo use a default scale and
  // precision
  PrimitiveTypeInfo primitiveTypeInfo = CALCITE_SQL_TYPE_2_HIVE_TYPE_INFO.get(
      sqlTypeName);
  if (primitiveTypeInfo == null) {
    throw new IllegalArgumentException(
        "can't find hive primitiveTypeInfo for Calcite SqlType: "
            + sqlTypeName);
  }
  ObjectInspector result;
  if (relDataTypeHolder.isConstant()) {
    Object value = relDataTypeHolder.getValue();
    Object hiveWritableValue = convertCalciteObject2HiveWritableObject(
        relDataTypeHolder,
        value);
    result =
        PrimitiveObjectInspectorFactory
            .getPrimitiveWritableConstantObjectInspector(
                primitiveTypeInfo, hiveWritableValue);
  } else {
    result =
        PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(
            primitiveTypeInfo);
  }

  return result;
}