Java Code Examples for io.crate.types.ArrayType#ID

The following examples show how to use io.crate.types.ArrayType#ID . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocIndexMetaData.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private ImmutableMap<ColumnIdent, String> getAnalyzers(ColumnIdent columnIdent, Map<String, Object> propertiesMap) {
    ImmutableMap.Builder<ColumnIdent, String> builder = ImmutableMap.builder();
    for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) {
        Map<String, Object> columnProperties = (Map) columnEntry.getValue();
        DataType columnDataType = getColumnDataType(columnProperties);
        ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());
        columnProperties = furtherColumnProperties(columnProperties);
        if (columnDataType == DataTypes.OBJECT
            || (columnDataType.id() == ArrayType.ID
                && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) {
            if (columnProperties.get("properties") != null) {
                builder.putAll(getAnalyzers(newIdent, (Map<String, Object>) columnProperties.get("properties")));
            }
        }
        String analyzer = (String) columnProperties.get("analyzer");
        if (analyzer != null) {
            builder.put(newIdent, analyzer);
        }
    }
    return builder.build();
}
 
Example 2
Source File: MoveReferenceCastToLiteralCastOnAnyOperatorsWhenRightIsReference.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Symbol apply(Function operator,
                    Captures captures,
                    Functions functions) {
    var literal = operator.arguments().get(0);
    var castFunction = captures.get(castCapture);
    var reference = castFunction.arguments().get(0);
    DataType<?> targetType = reference.valueType();
    if (targetType.id() != ArrayType.ID) {
        return null;
    }
    targetType = ((ArrayType<?>) targetType).innerType();

    var operatorName = operator.name();
    if (List.of(AnyOperators.Type.EQ.opName(), AnyOperators.Type.NEQ.opName()).contains(operatorName) == false
        && literal.valueType().id() == ArrayType.ID) {
        // this is not supported and will fail later on with more verbose error than a cast error
        return null;
    }

    return functionResolver.apply(
        operator.name(),
        List.of(literal.cast(targetType), reference)
    );
}
 
Example 3
Source File: DocIndexMetaData.java    From crate with Apache License 2.0 6 votes vote down vote up
private ImmutableMap<ColumnIdent, String> getAnalyzers(ColumnIdent columnIdent, Map<String, Object> propertiesMap) {
    ImmutableMap.Builder<ColumnIdent, String> builder = ImmutableMap.builder();
    for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) {
        Map<String, Object> columnProperties = (Map) columnEntry.getValue();
        DataType columnDataType = getColumnDataType(columnProperties);
        ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());
        columnProperties = furtherColumnProperties(columnProperties);
        if (columnDataType.id() == ObjectType.ID
            || (columnDataType.id() == ArrayType.ID
                && ((ArrayType) columnDataType).innerType().id() == ObjectType.ID)) {
            if (columnProperties.get("properties") != null) {
                builder.putAll(getAnalyzers(newIdent, (Map<String, Object>) columnProperties.get("properties")));
            }
        }
        String analyzer = (String) columnProperties.get("analyzer");
        if (analyzer != null) {
            builder.put(newIdent, analyzer);
        }
    }
    return builder.build();
}
 
Example 4
Source File: Unnest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static void validateTypes(List<? extends DataType> argumentTypes) {
    ListIterator<? extends DataType> it = argumentTypes.listIterator();
    if (!it.hasNext()) {
        throw new IllegalArgumentException("unnest expects at least 1 argument of type array. Got 0");
    }
    while (it.hasNext()) {
        DataType dataType = it.next();
        if (dataType.id() != ArrayType.ID) {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "unnest expects arguments of type array. " +
                    "Got an argument of type '%s' at position %d instead.", dataType, it.previousIndex()));
        }
    }
}
 
Example 5
Source File: SizeEstimatorFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> SizeEstimator<T> create(DataType<?> type) {
    switch (type.id()) {
        case UndefinedType.ID:
            return (SizeEstimator<T>) new ConstSizeEstimator(UNKNOWN_DEFAULT_RAM_BYTES_USED);

        case ObjectType.ID:
        case GeoShapeType.ID:
            return (SizeEstimator<T>) new SamplingSizeEstimator<>(SAMPLE_EVERY_NTH, MapSizeEstimator.INSTANCE);

        case StringType.ID:
        case IpType.ID:
            return (SizeEstimator<T>) StringSizeEstimator.INSTANCE;

        case ArrayType.ID:
            var innerEstimator = create(((ArrayType<?>) type).innerType());
            return (SizeEstimator<T>) ArraySizeEstimator.create(innerEstimator);

        case OidVectorType.ID:
            return (SizeEstimator<T>) ArraySizeEstimator.create(create(DataTypes.INTEGER));

        case RowType.ID:
            return (SizeEstimator<T>) new RecordSizeEstimator(Lists2.map(((RowType) type).fieldTypes(), SizeEstimatorFactory::create));

        case RegprocType.ID:
            return (SizeEstimator<T>) RegprocSizeEstimator.INSTANCE;

        default:
            if (type instanceof FixedWidthType) {
                return (SizeEstimator<T>) new ConstSizeEstimator(((FixedWidthType) type).fixedSize());
            }
            throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "Cannot get SizeEstimator for type %s", type));
    }
}
 
Example 6
Source File: UserDefinedFunctionMetaData.java    From crate with Apache License 2.0 5 votes vote down vote up
public static DataType<?> fromXContent(XContentParser parser) throws IOException {
    XContentParser.Token token = parser.currentToken();
    if (token != XContentParser.Token.START_OBJECT) {
        throw new IllegalArgumentException("Expected a START_OBJECT but got " + parser.currentToken());
    }
    int id = DataTypes.NOT_SUPPORTED.id();
    DataType<?> innerType = DataTypes.UNDEFINED;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            String fieldName = parser.currentName();
            if ("id".equals(fieldName)) {
                if (parser.nextToken() != XContentParser.Token.VALUE_NUMBER) {
                    throw new IllegalArgumentException("Expected a VALUE_NUMBER but got " + parser.currentToken());
                }
                id = parser.intValue();
            } else if ("inner_type".equals(fieldName)) {
                if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
                    throw new IllegalArgumentException("Expected a START_OBJECT but got " + parser.currentToken());
                }
                innerType = fromXContent(parser);
            }
        }
    }
    if (id == ArrayType.ID) {
        return new ArrayType<>(innerType);
    }
    return DataTypes.fromId(id);
}
 
Example 7
Source File: LuceneReferenceResolver.java    From crate with Apache License 2.0 5 votes vote down vote up
private static LuceneCollectorExpression<?> typeSpecializedExpression(final FieldTypeLookup fieldTypeLookup, final Reference ref) {
    final String fqn = ref.column().fqn();
    final MappedFieldType fieldType = fieldTypeLookup.get(fqn);
    if (fieldType == null) {
        return NO_FIELD_TYPES_IDS.contains(unnest(ref.valueType()).id()) || isIgnoredDynamicReference(ref)
            ? DocCollectorExpression.create(toSourceLookup(ref))
            : new NullValueCollectorExpression();
    }
    if (!fieldType.hasDocValues()) {
        return DocCollectorExpression.create(toSourceLookup(ref));
    }
    switch (ref.valueType().id()) {
        case ByteType.ID:
            return new ByteColumnReference(fqn);
        case ShortType.ID:
            return new ShortColumnReference(fqn);
        case IpType.ID:
            return new IpColumnReference(fqn);
        case StringType.ID:
            return new BytesRefColumnReference(fqn);
        case DoubleType.ID:
            return new DoubleColumnReference(fqn);
        case BooleanType.ID:
            return new BooleanColumnReference(fqn);
        case FloatType.ID:
            return new FloatColumnReference(fqn);
        case LongType.ID:
        case TimestampType.ID_WITH_TZ:
        case TimestampType.ID_WITHOUT_TZ:
            return new LongColumnReference(fqn);
        case IntegerType.ID:
            return new IntegerColumnReference(fqn);
        case GeoPointType.ID:
            return new GeoPointColumnReference(fqn);
        case ArrayType.ID:
            return DocCollectorExpression.create(toSourceLookup(ref));
        default:
            throw new UnhandledServerException("Unsupported type: " + ref.valueType().getName());
    }
}
 
Example 8
Source File: PolyglotValuesConverter.java    From crate with Apache License 2.0 5 votes vote down vote up
static Object toCrateObject(Value value, DataType<?> type) {
    if (value == null) {
        return null;
    }
    switch (type.id()) {
        case ArrayType.ID:
            ArrayList<Object> items = new ArrayList<>((int) value.getArraySize());
            for (int idx = 0; idx < value.getArraySize(); idx++) {
                var item = toCrateObject(value.getArrayElement(idx), ((ArrayType) type).innerType());
                items.add(idx, item);
            }
            return type.value(items);
        case ObjectType.ID:
            return type.value(value.as(MAP_TYPE_LITERAL));
        case GeoPointType.ID:
            if (value.hasArrayElements()) {
                return type.value(toCrateObject(value, DataTypes.DOUBLE_ARRAY));
            } else {
                return type.value(value.asString());
            }
        case GeoShapeType.ID:
            if (value.isString()) {
                return type.value(value.asString());
            } else {
                return type.value(value.as(MAP_TYPE_LITERAL));
            }
        default:
            final Object polyglotValue;
            if (value.isNumber()) {
                polyglotValue = value.as(NUMBER_TYPE_LITERAL);
            } else if (value.isString()) {
                polyglotValue = value.asString();
            } else if (value.isBoolean()) {
                polyglotValue = value.asBoolean();
            } else {
                polyglotValue = value.asString();
            }
            return type.value(polyglotValue);
    }
}
 
Example 9
Source File: CollectionCountFunction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private static boolean isCollectionType(DataType dataType) {
    return dataType.id() == ArrayType.ID || dataType.id() == SetType.ID;
}
 
Example 10
Source File: UpdateStatementAnalyzer.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public boolean apply(@Nullable ReferenceInfo input) {
    return input != null
            && input.type().id() == ArrayType.ID
            && ((ArrayType)input.type()).innerType().equals(DataTypes.OBJECT);
}
 
Example 11
Source File: AbstractTableRelation.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public boolean apply(@Nullable ReferenceInfo input) {
    return input != null
            && input.type().id() == ArrayType.ID
            && ((ArrayType) input.type()).innerType().equals(DataTypes.OBJECT);
}
 
Example 12
Source File: ValueNormalizer.java    From crate with Apache License 2.0 4 votes vote down vote up
private static boolean isObjectArray(DataType type) {
    return type.id() == ArrayType.ID && ((ArrayType) type).innerType().id() == ObjectType.ID;
}