Java Code Examples for org.apache.spark.unsafe.types.UTF8String#fromString()
The following examples show how to use
org.apache.spark.unsafe.types.UTF8String#fromString() .
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: SparkValueReaders.java From iceberg with Apache License 2.0 | 5 votes |
@Override public UTF8String read(Decoder decoder, Object reuse) throws IOException { ByteBuffer buffer = BUFFER.get(); buffer.rewind(); decoder.readFixed(buffer.array(), 0, 16); long mostSigBits = buffer.getLong(); long leastSigBits = buffer.getLong(); return UTF8String.fromString(new UUID(mostSigBits, leastSigBits).toString()); }
Example 2
Source File: RowDataReader.java From iceberg with Apache License 2.0 | 5 votes |
private static Object convertConstant(Type type, Object value) { if (value == null) { return null; } switch (type.typeId()) { case DECIMAL: return Decimal.apply((BigDecimal) value); case STRING: if (value instanceof Utf8) { Utf8 utf8 = (Utf8) value; return UTF8String.fromBytes(utf8.getBytes(), 0, utf8.getByteLength()); } return UTF8String.fromString(value.toString()); case FIXED: if (value instanceof byte[]) { return value; } else if (value instanceof GenericData.Fixed) { return ((GenericData.Fixed) value).bytes(); } return ByteBuffers.toByteArray((ByteBuffer) value); case BINARY: return ByteBuffers.toByteArray((ByteBuffer) value); default: } return value; }
Example 3
Source File: SparkValueReaders.java From iceberg with Apache License 2.0 | 5 votes |
@Override public UTF8String read(Decoder decoder, Object reuse) throws IOException { ByteBuffer buffer = BUFFER.get(); buffer.rewind(); decoder.readFixed(buffer.array(), 0, 16); long mostSigBits = buffer.getLong(); long leastSigBits = buffer.getLong(); return UTF8String.fromString(new UUID(mostSigBits, leastSigBits).toString()); }
Example 4
Source File: Reader.java From iceberg with Apache License 2.0 | 5 votes |
/** * Converts the objects into instances used by Spark's InternalRow. * * @param value a data value * @param type the Spark data type * @return the value converted to the representation expected by Spark's InternalRow. */ private static Object convert(Object value, DataType type) { if (type instanceof StringType) { return UTF8String.fromString(value.toString()); } else if (type instanceof BinaryType) { ByteBuffer buffer = (ByteBuffer) value; return buffer.get(new byte[buffer.remaining()]); } else if (type instanceof DecimalType) { return Decimal.fromDecimal(value); } return value; }
Example 5
Source File: Cast.java From indexr with Apache License 2.0 | 5 votes |
@Override public UTF8String evalString(InternalRow input) { if (childDataType == null) { childDataType = child.dataType(); } if (dataType == childDataType) { return child.evalString(input); } return UTF8String.fromString(TypeConverters.castToString(child.evalUniformVal(input), childDataType)); }
Example 6
Source File: Between.java From indexr with Apache License 2.0 | 5 votes |
@JsonCreator public Between(@JsonProperty("attr") Attr attr, @JsonProperty("numValue1") long numValue1, @JsonProperty("numValue2") long numValue2, @JsonProperty("strValue1") String strValue1, @JsonProperty("strValue2") String strValue2) { this(attr, numValue1, numValue2, strValue1 == null ? null : UTF8String.fromString(strValue1), strValue2 == null ? null : UTF8String.fromString(strValue2)); }
Example 7
Source File: In.java From indexr with Apache License 2.0 | 5 votes |
static UTF8String[] toUTF8Arr(String[] strValues) { if (strValues == null) { return null; } UTF8String[] vs = new UTF8String[strValues.length]; for (int i = 0; i < strValues.length; i++) { vs[i] = strValues[i] == null ? null : UTF8String.fromString(strValues[i]); } return vs; }
Example 8
Source File: StructInternalRow.java From iceberg with Apache License 2.0 | 4 votes |
@Override public UTF8String getUTF8String(int ordinal) { CharSequence seq = struct.get(ordinal, CharSequence.class); return UTF8String.fromString(seq.toString()); }
Example 9
Source File: SparkFilter.java From indexr with Apache License 2.0 | 4 votes |
private static FilterParam parseFilterParam(List<ColumnSchema> schemas, String name, Object value) { //if (true) { // throw new RuntimeException(String.format("class: %s, v: %s", value.getClass(), value)); //} try { ColumnSchema columnSchema = Trick.find(schemas, s -> s.getName().equalsIgnoreCase(name)); FilterParam param = new FilterParam(); param.attr = new Attr(columnSchema.getName(), columnSchema.getSqlType()); if (value instanceof Integer) { param.numValue = (Integer) value; } else if (value instanceof Long) { param.numValue = (Long) value; } else if (value instanceof Float) { param.numValue = Double.doubleToRawLongBits((Float) value); } else if (value instanceof Double) { param.numValue = Double.doubleToRawLongBits((Double) value); } else if (value instanceof String) { param.strValue = UTF8String.fromString((String) value); } else if (value instanceof Object[]) { List<Long> numValues = new ArrayList<>(); List<UTF8String> strValues = new ArrayList<>(); for (Object v : (Object[]) value) { if (v instanceof Integer) { numValues.add((long) (Integer) v); } else if (v instanceof Long) { numValues.add((Long) v); } else if (v instanceof Float) { numValues.add(Double.doubleToRawLongBits((Float) v)); } else if (v instanceof Double) { numValues.add(Double.doubleToRawLongBits((Double) v)); } else if (v instanceof String) { strValues.add(UTF8String.fromString((String) v)); } else { return null; } } if (!numValues.isEmpty()) { param.numValues = toLongArray(numValues); } else { param.strValues = strValues.toArray(new UTF8String[0]); } } else { return null; } return param; } catch (Exception e) { logger.warn("Failed to parse filter param value: {}", value, e); return null; } }
Example 10
Source File: Literal.java From indexr with Apache License 2.0 | 4 votes |
@Override public UTF8String evalString(InternalRow input) {return UTF8String.fromString(stringVal);}
Example 11
Source File: SegmentBenchmark.java From indexr with Apache License 2.0 | 4 votes |
@Override public UTF8String getString(int colId) { return UTF8String.fromString(String.valueOf(random.nextLong())); }
Example 12
Source File: ColCmpVal.java From indexr with Apache License 2.0 | 4 votes |
public ColCmpVal(Attr attr, long numValue, String strValue) { this(attr, numValue, strValue == null ? null : UTF8String.fromString(strValue)); }