Search in sources :

Example 1 with TimestampType

use of org.apache.spark.sql.types.TimestampType in project carbondata by apache.

the class CarbonColumnVectorWrapper method convertSparkToCarbonDataType.

// TODO: this is copied from carbondata-spark-common module, use presto type instead of this
private org.apache.carbondata.core.metadata.datatype.DataType convertSparkToCarbonDataType(org.apache.spark.sql.types.DataType dataType) {
    if (dataType instanceof StringType) {
        return DataTypes.STRING;
    } else if (dataType instanceof ShortType) {
        return DataTypes.SHORT;
    } else if (dataType instanceof IntegerType) {
        return DataTypes.INT;
    } else if (dataType instanceof LongType) {
        return DataTypes.LONG;
    } else if (dataType instanceof DoubleType) {
        return DataTypes.DOUBLE;
    } else if (dataType instanceof FloatType) {
        return DataTypes.FLOAT;
    } else if (dataType instanceof DateType) {
        return DataTypes.DATE;
    } else if (dataType instanceof BooleanType) {
        return DataTypes.BOOLEAN;
    } else if (dataType instanceof TimestampType) {
        return DataTypes.TIMESTAMP;
    } else if (dataType instanceof NullType) {
        return DataTypes.NULL;
    } else if (dataType instanceof DecimalType) {
        DecimalType decimal = (DecimalType) dataType;
        return DataTypes.createDecimalType(decimal.precision(), decimal.scale());
    } else if (dataType instanceof ArrayType) {
        org.apache.spark.sql.types.DataType elementType = ((ArrayType) dataType).elementType();
        return DataTypes.createArrayType(convertSparkToCarbonDataType(elementType));
    } else if (dataType instanceof StructType) {
        StructType structType = (StructType) dataType;
        org.apache.spark.sql.types.StructField[] fields = structType.fields();
        List<StructField> carbonFields = new ArrayList<>();
        for (org.apache.spark.sql.types.StructField field : fields) {
            carbonFields.add(new StructField(field.name(), convertSparkToCarbonDataType(field.dataType())));
        }
        return DataTypes.createStructType(carbonFields);
    } else {
        throw new UnsupportedOperationException("getting " + dataType + " from presto");
    }
}
Also used : LongType(org.apache.spark.sql.types.LongType) StructType(org.apache.spark.sql.types.StructType) StringType(org.apache.spark.sql.types.StringType) ArrayList(java.util.ArrayList) FloatType(org.apache.spark.sql.types.FloatType) ArrayType(org.apache.spark.sql.types.ArrayType) StructField(org.apache.carbondata.core.metadata.datatype.StructField) TimestampType(org.apache.spark.sql.types.TimestampType) DataType(org.apache.carbondata.core.metadata.datatype.DataType) DateType(org.apache.spark.sql.types.DateType) ShortType(org.apache.spark.sql.types.ShortType) BooleanType(org.apache.spark.sql.types.BooleanType) IntegerType(org.apache.spark.sql.types.IntegerType) DoubleType(org.apache.spark.sql.types.DoubleType) DecimalType(org.apache.spark.sql.types.DecimalType) NullType(org.apache.spark.sql.types.NullType)

Aggregations

ArrayList (java.util.ArrayList)1 DataType (org.apache.carbondata.core.metadata.datatype.DataType)1 StructField (org.apache.carbondata.core.metadata.datatype.StructField)1 ArrayType (org.apache.spark.sql.types.ArrayType)1 BooleanType (org.apache.spark.sql.types.BooleanType)1 DateType (org.apache.spark.sql.types.DateType)1 DecimalType (org.apache.spark.sql.types.DecimalType)1 DoubleType (org.apache.spark.sql.types.DoubleType)1 FloatType (org.apache.spark.sql.types.FloatType)1 IntegerType (org.apache.spark.sql.types.IntegerType)1 LongType (org.apache.spark.sql.types.LongType)1 NullType (org.apache.spark.sql.types.NullType)1 ShortType (org.apache.spark.sql.types.ShortType)1 StringType (org.apache.spark.sql.types.StringType)1 StructType (org.apache.spark.sql.types.StructType)1 TimestampType (org.apache.spark.sql.types.TimestampType)1