Package org.apache.sqoop.schema.type

Examples of org.apache.sqoop.schema.type.Column


  private static Column restoreColumn(JSONObject obj) {
    String name = (String) obj.get(NAME);

    Boolean nullable = (Boolean) obj.get(NULLABLE);
    Column key = null;
    if(obj.containsKey(KEY)) {
      key = restoreColumn((JSONObject) obj.get(KEY));
    }
    Column value = null;
    if(obj.containsKey(VALUE)) {
      value = restoreColumn((JSONObject) obj.get(VALUE));
    }
    Long size = (Long)obj.get(SIZE);
    Boolean fraction = (Boolean)obj.get(FRACTION);
    Boolean timezone = (Boolean)obj.get(TIMEZONE);
    Long precision = (Long)obj.get(PRECISION);
    Long scale = (Long)obj.get(SCALE);
    Boolean unsigned = (Boolean)obj.get(UNSIGNED);
    Long jdbcType = (Long)obj.get(JDBC_TYPE);

    Type type = Type.valueOf((String) obj.get(TYPE));
    Column output = null;
    switch (type) {
      case ARRAY:
        output = new Array(key);
        break;
      case BINARY:
        output = new Binary().setSize(size);
        break;
      case BIT:
        output = new Bit();
        break;
      case DATE:
        output = new Date();
        break;
      case DATE_TIME:
        output = new DateTime().setFraction(fraction).setTimezone(timezone);
        break;
      case DECIMAL:
        output = new Decimal().setPrecision(precision).setScale(scale);
        break;
      case ENUM:
        output = new Enum(key);
        break;
      case FIXED_POINT:
        output = new FixedPoint().setByteSize(size).setUnsigned(unsigned);
        break;
      case FLOATING_POINT:
        output = new FloatingPoint().setByteSize(size);
        break;
      case MAP:
        output = new Map(key, value);
        break;
      case SET:
        output = new Set(key);
        break;
      case TEXT:
        output = new Text().setSize(size);
        break;
      case TIME:
        output = new Time().setFraction(fraction);
        break;
      case UNSUPPORTED:
        output = new Unsupported().setJdbcType(jdbcType);
        break;
      default:
        // TODO(Jarcec): Throw an exception of unsupported type?
    }

    output.setName(name);
    output.setNullable(nullable);

    return output;
  }
View Full Code Here


          .replace(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN, "1 = 0")
      );

      rsmt = rs.getMetaData();
      for (int i = 1 ; i <= rsmt.getColumnCount(); i++) {
        Column column = SqlTypesUtils.sqlTypeToAbstractType(rsmt.getColumnType(i));

        String columnName = rsmt.getColumnName(i);
        if (columnName == null || columnName.equals("")) {
          columnName = rsmt.getColumnLabel(i);
          if (null == columnName) {
            columnName = "Column " + i;
          }
        }

        column.setName(columnName);
        schema.addColumn(column);
      }

      return schema;
    } catch (SQLException e) {
View Full Code Here

TOP

Related Classes of org.apache.sqoop.schema.type.Column

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.