List of usage examples for org.apache.spark.unsafe.types UTF8String fromBytes
public static UTF8String fromBytes(byte[] bytes)
From source file:com.github.sadikovi.riff.row.IndexedRow.java
License:Open Source License
/** Extract UTF8String from byte buffer */ private UTF8String getUTF8String(int ordinal, ByteBuffer buf) { // parse metadata, this should be in sync with converters: [offset + length] long metadata = buf.getLong(this.offsets[ordinal]); int offset = (int) (metadata >>> 32); int length = (int) (metadata & Integer.MAX_VALUE); byte[] bytes = new byte[length]; int oldPos = buf.position(); // need to reset buffer position, offset in get method is applied to buffer as well, so we // use 0 as array offset and shift position to offset buf.position(offset);// www.j ava2 s. c o m buf.get(bytes, 0, length); buf.position(oldPos); return UTF8String.fromBytes(bytes); }
From source file:com.github.sadikovi.riff.stats.UTF8Statistics.java
License:Open Source License
/** * Return deep copy of UTF8String, this method forcefully copies `getBytes()` bytes in * UTF8String, since it does not return copy when backed by single array. * Clone is null safe, and would return null for null input. * @param str UTF8 string to clone/*from www.jav a 2s. co m*/ * @return copy */ private UTF8String clone(UTF8String str) { if (str == null) return null; byte[] bytes = new byte[str.numBytes()]; System.arraycopy(str.getBytes(), 0, bytes, 0, bytes.length); return UTF8String.fromBytes(bytes); }
From source file:com.github.sadikovi.riff.stats.UTF8Statistics.java
License:Open Source License
@Override protected void readState(ByteBuffer buf) throws IOException { boolean isNull = buf.get() == 0; if (isNull) { min = null;// w w w . j a v a2 s . co m max = null; } else { int len = buf.getInt(); byte[] bytes = new byte[len]; buf.get(bytes); min = UTF8String.fromBytes(bytes); len = buf.getInt(); bytes = new byte[len]; buf.get(bytes); max = UTF8String.fromBytes(bytes); } }
From source file:com.github.sadikovi.riff.tree.expression.UTF8StringExpression.java
License:Open Source License
@Override public TypedExpression copy() { return new UTF8StringExpression(UTF8String.fromBytes(value.getBytes())); }
From source file:org.apache.carbondata.converter.SparkDataTypeConverterImpl.java
License:Apache License
@Override public Object convertFromByteToUTF8String(byte[] data) { if (null == data) { return null; }/*from w w w .j a v a2 s . c om*/ return UTF8String.fromBytes(data); }
From source file:org.apache.carbondata.converter.SparkDataTypeConverterImpl.java
License:Apache License
@Override public byte[] convertFromByteToUTF8Bytes(byte[] data) { return UTF8String.fromBytes(data).getBytes(); }
From source file:org.apache.carbondata.core.scan.executor.util.RestructureUtil.java
License:Apache License
/** * Method for computing default value for no dictionary * * @param defaultValue/*ww w . j ava 2 s.com*/ * @return */ private static Object getNoDictionaryDefaultValue(byte[] defaultValue) { Object noDictionaryDefaultValue = null; if (!isDefaultValueNull(defaultValue)) { noDictionaryDefaultValue = UTF8String.fromBytes(defaultValue); } return noDictionaryDefaultValue; }
From source file:org.apache.carbondata.core.scan.result.vector.impl.CarbonColumnVectorImpl.java
License:Apache License
@Override public Object getData(int rowId) { if (nullBytes.get(rowId)) { return null; }/*from w w w . ja va 2 s .c o m*/ switch (dataType) { case INT: return ints[rowId]; case LONG: return longs[rowId]; case DOUBLE: return doubles[rowId]; case STRING: return UTF8String.fromBytes(bytes[rowId]); case DECIMAL: return decimals[rowId]; default: return data[rowId]; } }
From source file:org.apache.hive.service.cli.ColumnValue.java
License:Apache License
public static TColumnValue toTColumnValue(TypeDescriptor typeDescriptor, Object value) { Type type = typeDescriptor.getType(); switch (type) { case BOOLEAN_TYPE: return booleanValue((Boolean) value); case TINYINT_TYPE: return byteValue((Byte) value); case SMALLINT_TYPE: return shortValue((Short) value); case INT_TYPE: return intValue((Integer) value); case BIGINT_TYPE: return longValue((Long) value); case FLOAT_TYPE: return floatValue((Float) value); case DOUBLE_TYPE: return doubleValue((Double) value); case STRING_TYPE: return stringValue((String) value); case CHAR_TYPE: return stringValue((HiveChar) value); case VARCHAR_TYPE: return stringValue((HiveVarchar) value); case DATE_TYPE: return dateValue((Date) value); case TIMESTAMP_TYPE: return timestampValue((Timestamp) value); case INTERVAL_YEAR_MONTH_TYPE: return stringValue((HiveIntervalYearMonth) value); case INTERVAL_DAY_TIME_TYPE: return stringValue((HiveIntervalDayTime) value); case DECIMAL_TYPE: return stringValue(((BigDecimal) value).toPlainString()); case BINARY_TYPE: String strVal = value == null ? null : UTF8String.fromBytes((byte[]) value).toString(); return stringValue(strVal); case ARRAY_TYPE: case MAP_TYPE: case STRUCT_TYPE: case UNION_TYPE: case USER_DEFINED_TYPE: return stringValue((String) value); case NULL_TYPE: return stringValue((String) value); default:/* w ww . j av a 2 s. co m*/ return null; } }
From source file:org.carbondata.query.complex.querytypes.PrimitiveQueryType.java
License:Apache License
@Override public Object getDataBasedOnDataTypeFromSurrogates(ByteBuffer surrogateData) { byte[] data = new byte[keySize]; surrogateData.get(data);// w w w . jav a 2 s .c om Bits bit = new Bits(new int[] { keySize * 8 }); int surrgateValue = (int) bit.getKeyArray(data)[0]; Object actualData = null; if (isDirectDictionary) { DirectDictionaryGenerator directDictionaryGenerator = DirectDictionaryKeyGeneratorFactory .getDirectDictionaryGenerator(dataType); actualData = directDictionaryGenerator.getValueFromSurrogate(surrgateValue); } else { String dictionaryValueForKey = dictionary.getDictionaryValueForKey(surrgateValue); actualData = DataTypeUtil.getDataBasedOnDataType(dictionaryValueForKey, this.dataType); } if (null != actualData && this.dataType == org.carbondata.core.carbon.metadata.datatype.DataType.STRING) { byte[] dataBytes = ((String) actualData).getBytes(Charset.defaultCharset()); return UTF8String.fromBytes(dataBytes); } return actualData; }