Search in sources :

Example 6 with MapType

use of com.netflix.metacat.common.type.MapType in project metacat by Netflix.

the class CassandraTypeConverter method fromMetacatType.

/**
 * {@inheritDoc}
 */
@Override
public String fromMetacatType(@Nonnull @NonNull final Type type) {
    switch(type.getTypeSignature().getBase()) {
        case ARRAY:
            if (!(type instanceof ArrayType)) {
                throw new IllegalArgumentException("Expected an ArrayType and got " + type.getClass());
            }
            final ArrayType arrayType = (ArrayType) type;
            return "list<" + this.getElementTypeString(arrayType.getElementType()) + ">";
        case BIGINT:
            return "bigint";
        case BOOLEAN:
            return "boolean";
        case CHAR:
            // TODO: Should we make this unsupported?
            return "text";
        case DATE:
            return "date";
        case DECIMAL:
            return "decimal";
        case DOUBLE:
            return "double";
        case FLOAT:
            return "float";
        case INT:
            return "int";
        case INTERVAL_DAY_TO_SECOND:
            throw new UnsupportedOperationException("Cassandra doesn't support intervals.");
        case INTERVAL_YEAR_TO_MONTH:
            throw new UnsupportedOperationException("Cassandra doesn't support intervals.");
        case JSON:
            throw new UnsupportedOperationException("Cassandra doesn't support JSON natively.");
        case MAP:
            if (!(type instanceof MapType)) {
                throw new IllegalArgumentException("Was expecting MapType instead it is " + type.getClass());
            }
            final MapType mapType = (MapType) type;
            final Type keyType = mapType.getKeyType();
            final Type valueType = mapType.getValueType();
            return "map<" + this.getElementTypeString(keyType) + ", " + this.getElementTypeString(valueType) + ">";
        case ROW:
            if (!(type instanceof RowType)) {
                throw new IllegalArgumentException("Was expecting RowType instead it is " + type.getClass());
            }
            final RowType rowType = (RowType) type;
            final StringBuilder tupleBuilder = new StringBuilder();
            tupleBuilder.append("tuple<");
            // Tuple fields don't need to be frozen
            boolean putComma = false;
            for (final RowType.RowField field : rowType.getFields()) {
                if (putComma) {
                    tupleBuilder.append(", ");
                } else {
                    putComma = true;
                }
                tupleBuilder.append(this.fromMetacatType(field.getType()));
            }
            tupleBuilder.append(">");
            return tupleBuilder.toString();
        case SMALLINT:
            return "smallint";
        case STRING:
            return "text";
        case TIME:
            return "time";
        case TIME_WITH_TIME_ZONE:
            throw new UnsupportedOperationException("Cassandra doesn't support time with timezone");
        case TIMESTAMP:
            return "timestamp";
        case TIMESTAMP_WITH_TIME_ZONE:
            throw new UnsupportedOperationException("Cassandra doesn't support time with timezone");
        case TINYINT:
            return "tinyint";
        case UNKNOWN:
            throw new UnsupportedOperationException("Cassandra doesn't support an unknown type");
        case VARBINARY:
            return "blob";
        case VARCHAR:
            return "text";
        default:
            throw new IllegalArgumentException("Unknown type: " + type.getTypeSignature().getBase());
    }
}
Also used : ArrayType(com.netflix.metacat.common.type.ArrayType) DecimalType(com.netflix.metacat.common.type.DecimalType) VarbinaryType(com.netflix.metacat.common.type.VarbinaryType) ArrayType(com.netflix.metacat.common.type.ArrayType) BaseType(com.netflix.metacat.common.type.BaseType) Type(com.netflix.metacat.common.type.Type) RowType(com.netflix.metacat.common.type.RowType) MapType(com.netflix.metacat.common.type.MapType) RowType(com.netflix.metacat.common.type.RowType) MapType(com.netflix.metacat.common.type.MapType)

Aggregations

MapType (com.netflix.metacat.common.type.MapType)6 RowType (com.netflix.metacat.common.type.RowType)6 DecimalType (com.netflix.metacat.common.type.DecimalType)5 ArrayType (com.netflix.metacat.common.type.ArrayType)4 CharType (com.netflix.metacat.common.type.CharType)4 Type (com.netflix.metacat.common.type.Type)4 VarcharType (com.netflix.metacat.common.type.VarcharType)4 BaseType (com.netflix.metacat.common.type.BaseType)3 ParametricType (com.netflix.metacat.common.type.ParametricType)2 VarbinaryType (com.netflix.metacat.common.type.VarbinaryType)2 LocalExecType (org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.LocalExecType)2 DataType (org.apache.pig.data.DataType)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 MetacatJsonLocator (com.netflix.metacat.common.json.MetacatJsonLocator)1 TypeEnum (com.netflix.metacat.common.type.TypeEnum)1 Matcher (java.util.regex.Matcher)1