Java Code Examples for org.elasticsearch.common.lucene.BytesRefs#toString()

The following examples show how to use org.elasticsearch.common.lucene.BytesRefs#toString() . 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: PartitionInfos.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Map<String, Object> buildValuesMap(PartitionName partitionName, MappingMetaData mappingMetaData) throws Exception{
    int i = 0;
    Map<String, Object> valuesMap = new HashMap<>();
    Iterable<Tuple<ColumnIdent, DataType>> partitionColumnInfoIterable = PartitionedByMappingExtractor.extractPartitionedByColumns(mappingMetaData.sourceAsMap());
    for (Tuple<ColumnIdent, DataType> columnInfo : partitionColumnInfoIterable) {
        String columnName = columnInfo.v1().sqlFqn();
        // produce string type values as string, not bytesref
        Object value = BytesRefs.toString(partitionName.values().get(i));
        if (!columnInfo.v2().equals(DataTypes.STRING)) {
            value = columnInfo.v2().value(value);
        }
        valuesMap.put(columnName, value);
        i++;
    }
    return valuesMap;
}
 
Example 2
Source File: RowShardResolver.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void setNextRow(Row row) {
    for (CollectExpression<Row, ?> expression : visitorContext.collectExpressions()) {
        expression.setNextRow(row);
    }
    id = idFunction.apply(pkValues(primaryKeyInputs));
    if (routingInput == null) {
        routing = null;
    } else {
        routing = BytesRefs.toString(routingInput.value());
    }
}
 
Example 3
Source File: Literal.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    return "Literal{" +
            "value=" + BytesRefs.toString(value) +
            ", type=" + type +
            '}';
}
 
Example 4
Source File: BytesRefUtils.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static String[] objectArrayToStringArray(Object[] values) {
    String[] strings = new String[values.length];
    for (int i = 0; i < strings.length; i++) {
        strings[i] = BytesRefs.toString(values[i]);
    }
    return strings;
}
 
Example 5
Source File: GeoJSONUtils.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static void validateGeoJson(Map value) {
    String type = BytesRefs.toString(value.get(TYPE_FIELD));
    if (type == null) {
        throw new IllegalArgumentException(invalidGeoJSON("type field missing"));
    }

    type = GEOSJON_TYPES.get(type);
    if (type == null) {
        throw new IllegalArgumentException(invalidGeoJSON("invalid type"));
    }

    if (GEOMETRY_COLLECTION.equals(type)) {
        Object geometries = value.get(GeoJSONUtils.GEOMETRIES_FIELD);
        if (geometries == null) {
            throw new IllegalArgumentException(invalidGeoJSON("geometries field missing"));
        }

        ForEach.forEach(geometries, new ForEach.Acceptor() {
            @Override
            public void accept(Object input) {
                if (!(input instanceof Map)) {
                    throw new IllegalArgumentException(invalidGeoJSON("invalid GeometryCollection"));
                } else {
                    validateGeoJson((Map)input);
                }
            }
        });
    } else {
        Object coordinates = value.get(COORDINATES_FIELD);
        if (coordinates == null) {
            throw new IllegalArgumentException(invalidGeoJSON("coordinates field missing"));
        }
        switch(type) {
            case POINT:
                validateCoordinate(coordinates);
                break;
            case MULTI_POINT:
            case LINE_STRING:
                validateCoordinates(coordinates, 1);
                break;
            case POLYGON:
            case MULTI_LINE_STRING:
                validateCoordinates(coordinates, 2);
                break;
            case MULTI_POLYGON:
                validateCoordinates(coordinates, 3);
                break;
            default:
                // shouldn't happen
                throw new IllegalArgumentException(invalidGeoJSON("invalid type"));
        }
    }
}
 
Example 6
Source File: GeoJSONUtils.java    From crate with Apache License 2.0 4 votes vote down vote up
public static void validateGeoJson(Map value) {
    String type = BytesRefs.toString(value.get(TYPE_FIELD));
    if (type == null) {
        throw new IllegalArgumentException(invalidGeoJSON("type field missing"));
    }

    type = GEOJSON_TYPES.get(type);
    if (type == null) {
        throw new IllegalArgumentException(invalidGeoJSON("invalid type"));
    }

    if (GEOMETRY_COLLECTION.equals(type)) {
        Object geometries = value.get(GeoJSONUtils.GEOMETRIES_FIELD);
        if (geometries == null) {
            throw new IllegalArgumentException(invalidGeoJSON("geometries field missing"));
        }

        ForEach.forEach(geometries, input -> {
            if (!(input instanceof Map)) {
                throw new IllegalArgumentException(invalidGeoJSON("invalid GeometryCollection"));
            } else {
                validateGeoJson((Map) input);
            }
        });
    } else {
        Object coordinates = value.get(COORDINATES_FIELD);
        if (coordinates == null) {
            throw new IllegalArgumentException(invalidGeoJSON("coordinates field missing"));
        }
        switch (type) {
            case POINT:
                validateCoordinate(coordinates);
                break;
            case MULTI_POINT:
            case LINE_STRING:
                validateCoordinates(coordinates, 1);
                break;
            case POLYGON:
            case MULTI_LINE_STRING:
                validateCoordinates(coordinates, 2);
                break;
            case MULTI_POLYGON:
                validateCoordinates(coordinates, 3);
                break;
            default:
                // shouldn't happen
                throw new IllegalArgumentException(invalidGeoJSON("invalid type"));
        }
    }
}