public Type toMetacatType()

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


    public Type toMetacatType(@Nonnull @NonNull final String type) {
        final Matcher matcher = TYPE_PATTERN.matcher(type.toLowerCase());
        // TODO: Escape case from recursion may be needed to avoid potential infinite
        if (matcher.matches()) {
            final String cqlType = matcher.group(TYPE_GROUP);
            switch (cqlType) {
                case "ascii":
                    return BaseType.STRING;
                case "bigint":
                    return BaseType.BIGINT;
                case "blob":
                    return VarbinaryType.createVarbinaryType(Integer.MAX_VALUE);
                case "boolean":
                    return BaseType.BOOLEAN;
                case "counter":
                    return BaseType.BIGINT;
                case "date":
                    return BaseType.DATE;
                case "decimal":
                    return DecimalType.createDecimalType();
                case "double":
                    return BaseType.DOUBLE;
                case "float":
                    return BaseType.FLOAT;
                case "frozen":
                    return this.toMetacatType(matcher.group(PARAM_GROUP));
                case "int":
                    return BaseType.INT;
                case "list":
                    // The possible null for the PARAM_GROUP should be handled on recursive call throwing exception
                    return new ArrayType(this.toMetacatType(matcher.group(PARAM_GROUP)));
                case "map":
                    final Matcher mapMatcher = MAP_PARAM_PATTERN.matcher(matcher.group(PARAM_GROUP));
                    if (mapMatcher.matches()) {
                        return new MapType(
                            this.toMetacatType(mapMatcher.group(MAP_KEY_GROUP)),
                            this.toMetacatType(mapMatcher.group(MAP_VALUE_GROUP))
                        );
                    } else {
                        throw new IllegalArgumentException("Unable to parse map params " + matcher.group(PARAM_GROUP));
                    }
                case "smallint":
                    return BaseType.SMALLINT;
                case "text":
                    return BaseType.STRING;
                case "time":
                    return BaseType.TIME;
                case "timestamp":
                    return BaseType.TIMESTAMP;
                case "tinyint":
                    return BaseType.TINYINT;
                case "tuple":
                    if (matcher.group(PARAM_GROUP) == null) {
                        throw new IllegalArgumentException("Empty tuple param group. Unable to parse");
                    }
                    final Matcher tupleMatcher = TUPLE_PARAM_PATTERN.matcher(matcher.group(PARAM_GROUP));
                    final ImmutableList.Builder<RowType.RowField> tupleFields = ImmutableList.builder();
                    int rowFieldNumber = 0;
                    while (tupleMatcher.find()) {
                        tupleFields.add(
                            new RowType.RowField(
                                this.toMetacatType(tupleMatcher.group(TUPLE_GROUP)),
                                "field" + rowFieldNumber++
                            )
                        );
                    }
                    return new RowType(tupleFields.build());
                case "varchar":
                    return BaseType.STRING;
                case "varint":
                    return BaseType.INT;
                case "inet":
                case "set":
                case "timeuuid":
                case "uuid":
                default:
                    log.info("Currently unsupported type {}, returning Unknown type", cqlType);
                    return BaseType.UNKNOWN;
            }
        } else {
            throw new IllegalArgumentException("Unable to parse CQL type " + type);
        }
    }