Java Code Examples for org.apache.calcite.sql.type.SqlTypeName#DYNAMIC_STAR

The following examples show how to use org.apache.calcite.sql.type.SqlTypeName#DYNAMIC_STAR . 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: RelDataTypeHolder.java    From Bats with Apache License 2.0 6 votes vote down vote up
public RelDataTypeField getField(RelDataTypeFactory typeFactory, String fieldName) {

    /* First check if this field name exists in our field list */
    for (RelDataTypeField f : fields) {
      if (fieldName.equalsIgnoreCase(f.getName())) {
        return f;
      }
    }

    /* This field does not exist in our field list add it */
    final SqlTypeName typeName = DynamicRecordType.isDynamicStarColName(fieldName)
        ? SqlTypeName.DYNAMIC_STAR : SqlTypeName.ANY;

    // This field does not exist in our field list add it
    RelDataTypeField newField = new RelDataTypeFieldImpl(
        fieldName,
        fields.size(),
        typeFactory.createTypeWithNullability(typeFactory.createSqlType(typeName), true));

    /* Add the name to our list of field names */
    fields.add(newField);

    return newField;
  }
 
Example 2
Source File: RelDataTypeHolder.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Get field if exists, otherwise inserts a new field. The new field by default will have "any"
 * type, except for the dynamic star field.
 *
 * @param fieldName Request field name
 * @param caseSensitive Case Sensitive
 * @return A pair of RelDataTypeField and Boolean. Boolean indicates whether a new field is added
 * to this holder.
 */
Pair<RelDataTypeField, Boolean> getFieldOrInsert(String fieldName, boolean caseSensitive) {
  // First check if this field name exists in our field list
  for (RelDataTypeField f : fields) {
    if (Util.matches(caseSensitive, f.getName(), fieldName)) {
      return Pair.of(f, false);
    }
    // A dynamic star field matches any field
    if (f.getType().getSqlTypeName() == SqlTypeName.DYNAMIC_STAR) {
      return Pair.of(f, false);
    }
  }

  final SqlTypeName typeName = DynamicRecordType.isDynamicStarColName(fieldName)
      ? SqlTypeName.DYNAMIC_STAR : SqlTypeName.ANY;

  // This field does not exist in our field list; add it
  RelDataTypeField newField = new RelDataTypeFieldImpl(
      fieldName,
      fields.size(),
      typeFactory.createTypeWithNullability(typeFactory.createSqlType(typeName), true));

  // Add the name to our list of field names
  fields.add(newField);

  return Pair.of(newField, true);
}
 
Example 3
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 4
Source File: RelDataTypeHolder.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Get field if exists, otherwise inserts a new field. The new field by default will have "any"
 * type, except for the dynamic star field.
 *
 * @param fieldName Request field name
 * @param caseSensitive Case Sensitive
 * @return A pair of RelDataTypeField and Boolean. Boolean indicates whether a new field is added
 * to this holder.
 */
Pair<RelDataTypeField, Boolean> getFieldOrInsert(String fieldName, boolean caseSensitive) {
  // First check if this field name exists in our field list
  for (RelDataTypeField f : fields) {
    if (Util.matches(caseSensitive, f.getName(), fieldName)) {
      return Pair.of(f, false);
    }
    // A dynamic star field matches any field
    if (f.getType().getSqlTypeName() == SqlTypeName.DYNAMIC_STAR) {
      return Pair.of(f, false);
    }
  }

  final SqlTypeName typeName = DynamicRecordType.isDynamicStarColName(fieldName)
      ? SqlTypeName.DYNAMIC_STAR : SqlTypeName.ANY;

  // This field does not exist in our field list; add it
  RelDataTypeField newField = new RelDataTypeFieldImpl(
      fieldName,
      fields.size(),
      typeFactory.createTypeWithNullability(typeFactory.createSqlType(typeName), true));

  // Add the name to our list of field names
  fields.add(newField);

  return Pair.of(newField, true);
}
 
Example 5
Source File: RelDataTypeFieldImpl.java    From Bats with Apache License 2.0 4 votes vote down vote up
public boolean isDynamicStar() {
  return type.getSqlTypeName() == SqlTypeName.DYNAMIC_STAR;
}
 
Example 6
Source File: RelDataTypeFieldImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
public boolean isDynamicStar() {
  return type.getSqlTypeName() == SqlTypeName.DYNAMIC_STAR;
}