List of usage examples for org.apache.spark.unsafe.types UTF8String fromString
public static UTF8String fromString(String str)
From source file:com.github.sadikovi.riff.tree.FilterApi.java
License:Open Source License
/** * Method to convert object into typed expression, throws exception if no match is found * @param obj object to convert, must never be null * @return typed expression for this object *///from w ww. j av a 2 s. co m protected static TypedExpression objToExpression(Object obj) { if (obj == null) { throw new NullPointerException("Cannot convert null into typed expression"); } if (obj instanceof Integer) { return new IntegerExpression((Integer) obj); } else if (obj instanceof Long) { return new LongExpression((Long) obj); } else if (obj instanceof String) { return new UTF8StringExpression(UTF8String.fromString((String) obj)); } else if (obj instanceof UTF8String) { return new UTF8StringExpression((UTF8String) obj); } else if (obj instanceof Date) { return new DateExpression((Date) obj); } else if (obj instanceof Timestamp) { return new TimestampExpression((Timestamp) obj); } else if (obj instanceof Boolean) { return new BooleanExpression((Boolean) obj); } else if (obj instanceof Short) { return new ShortExpression((Short) obj); } else if (obj instanceof Byte) { return new ByteExpression((Byte) obj); } else { throw new UnsupportedOperationException("Object " + obj + " of " + obj.getClass()); } }
From source file:com.hurence.logisland.connect.source.KafkaConnectStreamSource.java
License:Apache License
private UTF8String toUTFString(Object o) { if (o != null) { return UTF8String.fromString(o.toString()); }/*from w w w . ja va 2 s . c o m*/ return UTF8String.EMPTY_UTF8; }
From source file:com.splicemachine.db.iapi.types.SQLChar.java
License:Apache License
/** * * Write into the Project Tungsten Format (UnsafeRow). * * @see UnsafeRowWriter#write(int, UTF8String) * * @param unsafeRowWriter/*from w w w.j a v a 2 s. c om*/ * @param ordinal */ @Override public void write(UnsafeRowWriter unsafeRowWriter, int ordinal) { if (isNull()) unsafeRowWriter.setNullAt(ordinal); else { unsafeRowWriter.write(ordinal, UTF8String.fromString(value)); } }
From source file:org.apache.carbondata.converter.SparkDataTypeConverterImpl.java
License:Apache License
@Override public byte[] convertFromStringToByte(Object data) { if (null == data) { return null; }/*w w w. j a va 2s .c o m*/ return UTF8String.fromString((String) data).getBytes(); }
From source file:org.apache.carbondata.converter.SparkDataTypeConverterImpl.java
License:Apache License
@Override public Object convertFromStringToUTF8String(Object data) { if (null == data) { return null; }/* w w w . ja v a 2s . c om*/ return UTF8String.fromString((String) data); }
From source file:org.apache.carbondata.core.scan.collector.impl.RestructureBasedRawResultCollector.java
License:Apache License
/** * This method will fill the no dictionary byte array with newly added no dictionary columns * * @param noDictionaryKeyArray/*from w w w. j a v a 2s . c o m*/ * @return */ private byte[][] fillNoDictionaryKeyArrayWithLatestSchema(byte[][] noDictionaryKeyArray) { QueryDimension[] actualQueryDimensions = tableBlockExecutionInfos.getActualQueryDimensions(); byte[][] noDictionaryKeyArrayWithNewlyAddedColumns = new byte[noDictionaryKeyArray.length + dimensionInfo.getNewNoDictionaryColumnCount()][]; int existingColumnValueIndex = 0; int newKeyArrayIndex = 0; for (int i = 0; i < dimensionInfo.getDimensionExists().length; i++) { if (!actualQueryDimensions[i].getDimension().hasEncoding(Encoding.DICTIONARY) && !actualQueryDimensions[i].getDimension().hasEncoding(Encoding.IMPLICIT)) { // if dimension exists then add the byte array value else add the default value if (dimensionInfo.getDimensionExists()[i]) { noDictionaryKeyArrayWithNewlyAddedColumns[newKeyArrayIndex++] = noDictionaryKeyArray[existingColumnValueIndex++]; } else { byte[] newColumnDefaultValue = null; Object defaultValue = dimensionInfo.getDefaultValues()[i]; if (null != defaultValue) { newColumnDefaultValue = ((UTF8String) defaultValue).getBytes(); } else { newColumnDefaultValue = UTF8String.fromString(CarbonCommonConstants.MEMBER_DEFAULT_VAL) .getBytes(); } noDictionaryKeyArrayWithNewlyAddedColumns[newKeyArrayIndex++] = newColumnDefaultValue; } } } return noDictionaryKeyArrayWithNewlyAddedColumns; }
From source file:org.apache.carbondata.core.util.DataTypeUtil.java
License:Apache License
/** * Below method will be used to convert the data passed to its actual data * type//w w w . j av a 2s . c o m * * @param data data * @param actualDataType actual data type * @return actual data after conversion */ public static Object getDataBasedOnDataType(String data, DataType actualDataType) { if (null == data || CarbonCommonConstants.MEMBER_DEFAULT_VAL.equals(data)) { return null; } try { switch (actualDataType) { case INT: if (data.isEmpty()) { return null; } return Integer.parseInt(data); case SHORT: if (data.isEmpty()) { return null; } return Short.parseShort(data); case DOUBLE: if (data.isEmpty()) { return null; } return Double.parseDouble(data); case LONG: if (data.isEmpty()) { return null; } return Long.parseLong(data); case TIMESTAMP: if (data.isEmpty()) { return null; } SimpleDateFormat parser = new SimpleDateFormat( CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT)); Date dateToStr = null; try { dateToStr = parser.parse(data); return dateToStr.getTime() * 1000; } catch (ParseException e) { LOGGER.error("Cannot convert" + data + " to Time/Long type value" + e.getMessage()); return null; } case DECIMAL: if (data.isEmpty()) { return null; } java.math.BigDecimal javaDecVal = new java.math.BigDecimal(data); scala.math.BigDecimal scalaDecVal = new scala.math.BigDecimal(javaDecVal); org.apache.spark.sql.types.Decimal decConverter = new org.apache.spark.sql.types.Decimal(); return decConverter.set(scalaDecVal); default: return UTF8String.fromString(data); } } catch (NumberFormatException ex) { LOGGER.error("Problem while converting data type" + data); return null; } }
From source file:org.apache.carbondata.spark.readsupport.SparkRowReadSupportImpl.java
License:Apache License
@Override public Row readRow(Object[] data) { for (int i = 0; i < dictionaries.length; i++) { if (dictionaries[i] != null) { data[i] = DataTypeUtil.getDataBasedOnDataType( dictionaries[i].getDictionaryValueForKey((int) data[i]), dataTypes[i]); switch (dataTypes[i]) { case STRING: data[i] = UTF8String.fromString(data[i].toString()); break; case TIMESTAMP: data[i] = new Timestamp((long) data[i] / 1000); break; default: }//from www . j av a 2 s . co m } else if (carbonColumns[i].hasEncoding(Encoding.DIRECT_DICTIONARY)) { //convert the long to timestamp in case of direct dictionary column if (DataType.TIMESTAMP == carbonColumns[i].getDataType()) { data[i] = new Timestamp((long) data[i] / 1000); } } } return new GenericRow(data); }
From source file:org.carbondata.scan.util.DataTypeUtil.java
License:Apache License
/** * Below method will be used to convert the data passed to its actual data * type/*from ww w. jav a 2 s . c o m*/ * * @param data data * @param actualDataType actual data type * @return actual data after conversion */ public static Object getDataBasedOnDataType(String data, DataType actualDataType) { if (null == data || data.isEmpty()) { return null; } try { switch (actualDataType) { case INT: return Integer.parseInt(data); case SHORT: return Short.parseShort(data); case DOUBLE: return Double.parseDouble(data); case LONG: return Long.parseLong(data); case TIMESTAMP: SimpleDateFormat parser = new SimpleDateFormat( CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT)); Date dateToStr = null; try { dateToStr = parser.parse(data); return dateToStr.getTime() * 1000; } catch (ParseException e) { LOGGER.error("Cannot convert" + data + " to Time/Long type value" + e.getMessage()); return null; } case DECIMAL: java.math.BigDecimal javaDecVal = new java.math.BigDecimal(data); scala.math.BigDecimal scalaDecVal = new scala.math.BigDecimal(javaDecVal); org.apache.spark.sql.types.Decimal decConverter = new org.apache.spark.sql.types.Decimal(); return decConverter.set(scalaDecVal); default: return UTF8String.fromString(data); } } catch (NumberFormatException ex) { LOGGER.error("Problem while converting data type" + data); return null; } }