public String fromMetacatType()

in metacat-connector-cassandra/src/main/java/com/netflix/metacat/connector/cassandra/CassandraTypeConverter.java [151:232]


    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());
        }
    }