/** * Convert input string to a double, at position i in the respective vectors. */ @Override protected void func(DoubleColumnVector outV, BytesColumnVector inV, int batchIndex) { byte[] bytes = inV.vector[batchIndex]; final int start = inV.start[batchIndex]; final int length = inV.length[batchIndex]; try { if (!LazyUtils.isNumberMaybe(bytes, start, length)) { outV.noNulls = false; outV.isNull[batchIndex] = true; outV.vector[batchIndex] = DoubleColumnVector.NULL_VALUE; return; } outV.vector[batchIndex] = Float.parseFloat( new String(bytes, start, length, StandardCharsets.UTF_8)); } catch (Exception e) { // for any exception in conversion to integer, produce NULL outV.noNulls = false; outV.isNull[batchIndex] = true; outV.vector[batchIndex] = DoubleColumnVector.NULL_VALUE; } } }
/** * Convert input string to a double, at position i in the respective vectors. */ protected void func(DoubleColumnVector outputColVector, BytesColumnVector inputColVector, int batchIndex) { byte[] bytes = inputColVector.vector[batchIndex]; final int start = inputColVector.start[batchIndex]; final int length = inputColVector.length[batchIndex]; try { if (!LazyUtils.isNumberMaybe(bytes, start, length)) { outputColVector.noNulls = false; outputColVector.isNull[batchIndex] = true; outputColVector.vector[batchIndex] = DoubleColumnVector.NULL_VALUE; return; } outputColVector.vector[batchIndex] = StringToDouble.strtod(bytes, start, length); } catch (Exception e) { // for any exception in conversion to integer, produce NULL outputColVector.noNulls = false; outputColVector.isNull[batchIndex] = true; outputColVector.vector[batchIndex] = DoubleColumnVector.NULL_VALUE; } }
/** * Convert from string to a double. This is called for CAST(... AS DOUBLE) * * @param i * The string value to convert * @return DoubleWritable */ public DoubleWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { doubleWritable.set(Double.parseDouble(i.toString())); return doubleWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed double value. // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a float. This is called for CAST(... AS FLOAT) * * @param i * The string value to convert * @return FloatWritable */ public FloatWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { floatWritable.set(Float.parseFloat(i.toString())); return floatWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a byte. This is called for CAST(... AS TINYINT) * * @param i * The string value to convert * @return Byte */ public ByteWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { byteWritable.set(LazyByte.parseByte(i.getBytes(), 0, i.getLength(), 10, true)); return byteWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return Byte.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a short. This is called for CAST(... AS SMALLINT) * * @param i * The string value to convert * @return ShortWritable */ public ShortWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { shortWritable.set(LazyShort.parseShort(i.getBytes(), 0, i.getLength(), 10, true)); return shortWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return Byte.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a long. This is called for CAST(... AS BIGINT) * * @param i * The string value to convert * @return LongWritable */ public LongWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { longWritable .set(LazyLong.parseLong(i.getBytes(), 0, i.getLength(), 10, true)); return longWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return LongWritable.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a float. This is called for CAST(... AS FLOAT) * * @param i * The string value to convert * @return FloatWritable */ public FloatWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { floatWritable.set(Float.parseFloat(i.toString())); return floatWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a double. This is called for CAST(... AS DOUBLE) * * @param i * The string value to convert * @return DoubleWritable */ public DoubleWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { doubleWritable.set(Double.parseDouble(i.toString())); return doubleWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed double value. // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to an integer. This is called for CAST(... AS INT) * * @param i * The string value to convert * @return IntWritable */ public IntWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { intWritable.set(LazyInteger .parseInt(i.getBytes(), 0, i.getLength(), 10, true)); return intWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return IntWritable.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to an integer. This is called for CAST(... AS INT) * * @param i * The string value to convert * @return IntWritable */ public IntWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { intWritable.set(LazyInteger .parseInt(i.getBytes(), 0, i.getLength(), 10)); return intWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return IntWritable.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a byte. This is called for CAST(... AS TINYINT) * * @param i * The string value to convert * @return Byte */ public ByteWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { byteWritable.set(LazyByte.parseByte(i.getBytes(), 0, i.getLength(), 10)); return byteWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return Byte.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a long. This is called for CAST(... AS BIGINT) * * @param i * The string value to convert * @return LongWritable */ public LongWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { longWritable .set(LazyLong.parseLong(i.getBytes(), 0, i.getLength(), 10)); return longWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return LongWritable.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
/** * Convert from string to a short. This is called for CAST(... AS SMALLINT) * * @param i * The string value to convert * @return ShortWritable */ public ShortWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { shortWritable.set(LazyShort.parseShort(i.getBytes(), 0, i.getLength(), 10)); return shortWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return Byte.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
@Override public void init(ByteArrayRef bytes, int start, int length) { String byteData = null; if (!LazyUtils.isNumberMaybe(bytes.getData(), start, length)) { isNull = true; return; } try { byteData = Text.decode(bytes.getData(), start, length); data.set(Double.parseDouble(byteData)); isNull = false; } catch (NumberFormatException e) { isNull = true; LOG.debug("Data not in the Double data type range so converted to null. Given data is :" + byteData, e); } catch (CharacterCodingException e) { isNull = true; LOG.debug("Data not in the Double data type range so converted to null.", e); } }
@Override public void init(ByteArrayRef bytes, int start, int length) { String byteData = null; if (!LazyUtils.isNumberMaybe(bytes.getData(), start, length)) { isNull = true; return; } try { byteData = Text.decode(bytes.getData(), start, length); data.set(Float.parseFloat(byteData)); isNull = false; } catch (NumberFormatException e) { isNull = true; LOG.debug("Data not in the Float data type range so converted to null. Given data is :" + byteData, e); } catch (CharacterCodingException e) { isNull = true; LOG.debug("Data not in the Float data type range so converted to null.", e); } }
@Override public void init(ByteArrayRef bytes, int start, int length) { if (!LazyUtils.isNumberMaybe(bytes.getData(), start, length)) { isNull = true; return; } try { data.set(parseLong(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "BIGINT"); } }
@Override public void init(ByteArrayRef bytes, int start, int length) { if (!LazyUtils.isNumberMaybe(bytes.getData(), start, length)) { isNull = true; return; } try { data.set(parseByte(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "TINYINT"); } }
@Override public void init(ByteArrayRef bytes, int start, int length) { if (!LazyUtils.isNumberMaybe(bytes.getData(), start, length)) { isNull = true; return; } try { data.set(parseInt(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "INT"); } }
@Override public void init(ByteArrayRef bytes, int start, int length) { if (!LazyUtils.isNumberMaybe(bytes.getData(), start, length)) { isNull = true; return; } try { data.set(parseShort(bytes.getData(), start, length)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "SMALLINT"); } }