Package org.eigenbase.sql.type

Examples of org.eigenbase.sql.type.SqlTypeName


    final Primitive primitive = Primitive.ofBoxOr(physType.fieldClass(i));
    final RelDataType fieldType =
        physType.getRowType().getFieldList().get(i).getType();
    final List<Expression> dateTimeArgs = new ArrayList<Expression>();
    dateTimeArgs.add(Expressions.constant(i + 1));
    SqlTypeName sqlTypeName = fieldType.getSqlTypeName();
    boolean offset = false;
    switch (calendarPolicy) {
    case LOCAL:
      dateTimeArgs.add(calendar_);
      break;
View Full Code Here


    return RelDataTypeImpl.proto(fieldInfo.build());
  }

  private RelDataType sqlType(RelDataTypeFactory typeFactory, int dataType,
      int precision, int scale, String typeString) {
    SqlTypeName sqlTypeName = SqlTypeName.getNameForJdbcType(dataType);
    switch (sqlTypeName) {
    case ARRAY:
      RelDataType component = null;
      if (typeString != null && typeString.endsWith(" ARRAY")) {
        // E.g. hsqldb gives "INTEGER ARRAY", so we deduce the component type
        // "INTEGER".
        final String remaining = typeString.substring(0,
            typeString.length() - " ARRAY".length());
        component = parseTypeString(typeFactory, remaining);
      }
      if (component == null) {
        component = typeFactory.createSqlType(SqlTypeName.ANY);
      }
      return typeFactory.createArrayType(component, -1);
    }
    if (precision >= 0
        && scale >= 0
        && sqlTypeName.allowsPrecScale(true, true)) {
      return typeFactory.createSqlType(sqlTypeName, precision, scale);
    } else if (precision >= 0 && sqlTypeName.allowsPrecNoScale()) {
      return typeFactory.createSqlType(sqlTypeName, precision);
    } else {
      assert sqlTypeName.allowsNoPrecNoScale();
      return typeFactory.createSqlType(sqlTypeName);
    }
  }
View Full Code Here

          precision = Integer.parseInt(rest);
        }
      }
    }
    try {
      final SqlTypeName typeName = SqlTypeName.valueOf(typeString);
      return typeName.allowsPrecScale(true, true)
          ? typeFactory.createSqlType(typeName, precision, scale)
          : typeName.allowsPrecScale(true, false)
          ? typeFactory.createSqlType(typeName, precision)
          : typeFactory.createSqlType(typeName);
    } catch (IllegalArgumentException e) {
      return typeFactory.createSqlType(SqlTypeName.ANY);
    }
View Full Code Here

  }

  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());
      }
View Full Code Here

                    }
                    String name = fieldNames[Integer.valueOf(ordinal)];
                    s = s.concat(name);
                } else { // RexLiteral
                    RexLiteral lit = (RexLiteral) operands[i];
                    SqlTypeName litSqlType = lit.getTypeName();
                    if (litSqlType.equals(SqlTypeName.CHAR)) {
                        s = s.concat(
                            "'"
                            + ((NlsString) lit.getValue()).getValue().toString()
                            + "'");
                    } else if (
                        litSqlType.equals(SqlTypeName.TIMESTAMP)
                        || litSqlType.equals(SqlTypeName.DATE))
                    {
                        SimpleDateFormat sdf;
                        if (litSqlType.equals(SqlTypeName.TIMESTAMP)) {
                            sdf =
                                new SimpleDateFormat(
                                    "yyyy-MM-dd'T'HH:mm:ss'Z'");
                        } else {
                            sdf = new SimpleDateFormat("yyyy-MM-dd");
                        }
                        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
                        StringBuffer sbuf = new StringBuffer();
                        String time =
                            sdf.format(
                                ((Calendar) ((RexLiteral) lit).getValue())
                                .getTime(),
                                sbuf,
                                new FieldPosition(0)).toString();
                        s = s.concat(time);
                    } else if (
                        litSqlType.equals(SqlTypeName.DECIMAL)
                        || litSqlType.equals(SqlTypeName.DOUBLE))
                    {
                        if (litSqlType.equals(SqlTypeName.DECIMAL)) {
                            s = s.concat(
                                ((BigDecimal) lit.getValue()).toBigInteger()
                                                             .toString());
                        } else {
                            s = s.concat(
View Full Code Here

        return pattern;
    }

    protected RelDataType toRelType(Field field, FarragoTypeFactory typeFactory)
    {
        SqlTypeName typeName = convertSfdcSqlToSqlType(field.getType());
        if (typeName.allowsPrec()) {
            if (typeName.allowsScale()) { // only decimal type
                int maxPrecision = SqlTypeName.DECIMAL.MAX_NUMERIC_PRECISION;
                int precision = field.getPrecision();
                int scale = field.getScale();
                if ((precision > maxPrecision) || (scale > precision)) {
                    precision = maxPrecision;
                    int cappedScale = 6;
                    if (scale > cappedScale) {
                        scale = cappedScale;
                    }
                }
                if (scale < 0) {
                    scale = 0;
                }
                return typeFactory.createTypeWithNullability(
                    typeFactory.createSqlType(typeName, precision, scale),
                    true);
            } else {
                int precision = field.getPrecision();
                String fieldType = field.getType().getValue().toLowerCase();
                if (typeName.equals(SqlTypeName.TIMESTAMP)
                    || typeName.equals(SqlTypeName.TIME))
                {
                    precision = typeName.getDefaultPrecision();
                } else if (fieldType.equals("boolean")) {
                    precision = 5;
                } else {
                    precision = field.getLength() + varcharPrecision;
                    if (precision == 0) {
View Full Code Here

      this.TABLE_SCHEMA = schemaName;
      this.TABLE_NAME = tableName;

      this.COLUMN_NAME = field.getName();
      RelDataType type = field.getType();
      SqlTypeName sqlType = type.getSqlTypeName();

      this.ORDINAL_POSITION = field.getIndex();
      this.IS_NULLABLE = type.isNullable() ? "YES" : "NO";

      if (sqlType == SqlTypeName.ARRAY || sqlType == SqlTypeName.MAP || sqlType == SqlTypeName.ROW) {
        // For complex types use the toString method to display the inside elements
        String typeString = type.toString();

        // RelDataType.toString prints "RecordType" for "STRUCT".
        this.DATA_TYPE = type.toString().replace("RecordType", "STRUCT");
      } else {
        this.DATA_TYPE = sqlType.toString();
      }

      this.NUMERIC_PRECISION_RADIX = (sqlType == SqlTypeName.DECIMAL) ? 10 : -1; // TODO: where do we get radix?

      if (sqlType == SqlTypeName.VARCHAR) {
        // Max length is stored as precision in Optiq.
        this.CHARACTER_MAXIMUM_LENGTH = (sqlType.allowsPrec()) ? type.getPrecision() : -1;
        this.NUMERIC_PRECISION = -1;
      } else {
        this.CHARACTER_MAXIMUM_LENGTH = -1;
        this.NUMERIC_PRECISION = (sqlType.allowsPrec()) ? type.getPrecision() : -1;
      }

      this.NUMERIC_SCALE = (sqlType.allowsScale())?type.getScale(): -1;
    }
View Full Code Here

  }

  static ASTNode literal(RexLiteral literal, boolean useTypeQualInLiteral) {
    Object val = null;
    int type = 0;
    SqlTypeName sqlType = literal.getType().getSqlTypeName();

    switch (sqlType) {
    case BINARY:
      ByteString bs = (ByteString) literal.getValue();
      val = bs.byteAt(0);
View Full Code Here

        builder.add((String) jsonMap.get("name"), toType(typeFactory, jsonMap));
      }
      return builder.build();
    } else {
      final Map<String, Object> map = (Map<String, Object>) o;
      final SqlTypeName sqlTypeName =
          Util.enumVal(SqlTypeName.class, (String) map.get("type"));
      final Integer precision = (Integer) map.get("precision");
      final Integer scale = (Integer) map.get("scale");
      final RelDataType type;
      if (precision == null) {
View Full Code Here

        RelDataType type = toType(cluster.getTypeFactory(), jsonType);
        return rexBuilder.makeCorrel(type, correl);
      }
      if (map.containsKey("literal")) {
        final Object literal = map.get("literal");
        final SqlTypeName sqlTypeName =
            Util.enumVal(SqlTypeName.class, (String) map.get("type"));
        if (literal == null) {
          return rexBuilder.makeNullLiteral(sqlTypeName);
        }
        return toRex(relInput, literal);
View Full Code Here

TOP

Related Classes of org.eigenbase.sql.type.SqlTypeName

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.