if (row.isNullAt(fieldIdx)) { col.putNulls(0, capacity); } else { if (t == DataTypes.BooleanType) { col.putBooleans(0, capacity, row.getBoolean(fieldIdx)); } else if (t == DataTypes.ByteType) { col.putBytes(0, capacity, row.getByte(fieldIdx)); } else if (t == DataTypes.ShortType) { col.putShorts(0, capacity, row.getShort(fieldIdx)); } else if (t == DataTypes.IntegerType) { col.putInts(0, capacity, row.getInt(fieldIdx)); } else if (t == DataTypes.LongType) { col.putLongs(0, capacity, row.getLong(fieldIdx)); } else if (t == DataTypes.FloatType) { col.putFloats(0, capacity, row.getFloat(fieldIdx)); } else if (t == DataTypes.DoubleType) { col.putDoubles(0, capacity, row.getDouble(fieldIdx)); } else if (t == DataTypes.StringType) { UTF8String v = row.getUTF8String(fieldIdx); byte[] bytes = v.getBytes(); for (int i = 0; i < capacity; i++) { Decimal d = row.getDecimal(fieldIdx, dt.precision(), dt.scale()); if (dt.precision() <= Decimal.MAX_INT_DIGITS()) { col.putInts(0, capacity, (int)d.toUnscaledLong()); CalendarInterval c = (CalendarInterval)row.get(fieldIdx, t); col.getChildColumn(0).putInts(0, capacity, c.months); col.getChildColumn(1).putLongs(0, capacity, c.microseconds);
@Override public InternalRow serialize(T obj) { byte[] bytes = new TWKBWriter().write(obj); InternalRow returnRow = new GenericInternalRow(bytes.length); returnRow.update(0, bytes); return returnRow; }
@Override public void write(InternalRow internalRow) throws IOException { try { int i=0; for (StructField field : schema.fields()) { DataType dataType = field.dataType(); if (internalRow.isNullAt(i)) { statement.setNull(i + 1, SparkJdbcUtil.getJdbcType(dataType, PhoenixJdbcDialect$.MODULE$).jdbcNullType()); } else { Row row = SparkJdbcUtil.toRow(schema, internalRow); SparkJdbcUtil.makeSetter(conn, PhoenixJdbcDialect$.MODULE$, dataType).apply(statement, row, i); } ++i; } statement.execute(); } catch (SQLException e) { throw new IOException("Exception while executing Phoenix prepared statement", e); } }
@Override @SuppressWarnings("unchecked") public <T> T get(int pos, Class<T> javaClass) { return javaClass.cast(row.get(pos, types[pos])); }
if (partitionValues.numFields() > 0) { int partitionIdx = requiredFields.length; for (int i = 0; i < partitionValues.numFields(); i++) { ColumnVectorUtils.populate(columnVectors[i + partitionIdx], partitionValues, i); columnVectors[i + partitionIdx].setIsConstant(); if (partitionValues.numFields() > 0) { int partitionIdx = requiredFields.length; for (int i = 0; i < partitionValues.numFields(); i++) { DataType dt = partitionSchema.fields()[i].dataType(); OnHeapColumnVector partitionCol = new OnHeapColumnVector(capacity, dt);
@Override public Object get(InternalRow row) { InternalRow inner = row.getStruct(p, size); if (inner != null) { return accessor.get(inner); } return null; } }
@SuppressWarnings("unchecked") public static <T> StructType reflectSchema(final Class<T> beanClass) { return (StructType) JavaTypeInference.inferDataType(beanClass)._1(); }
@Override public Object[] parserRow(InternalRow row) { return csvParser.parseLine(row.getString(0)); }
private void initBatch() { initBatch(DEFAULT_MEMORY_MODE, new StructType(), InternalRow.empty()); }
@Override public T deserialize(Object datum) { T geom = null; InternalRow row = (InternalRow) datum; byte[] bytes = row.getBinary(0); try { geom = (T) new TWKBReader().read(bytes); } catch (ParseException e) { e.printStackTrace(); } return geom; } }
if (row.isNullAt(fieldIdx)) { col.putNulls(0, capacity); } else { if (t == DataTypes.BooleanType) { col.putBooleans(0, capacity, row.getBoolean(fieldIdx)); } else if (t == DataTypes.ByteType) { col.putBytes(0, capacity, row.getByte(fieldIdx)); } else if (t == DataTypes.ShortType) { col.putShorts(0, capacity, row.getShort(fieldIdx)); } else if (t == DataTypes.IntegerType) { col.putInts(0, capacity, row.getInt(fieldIdx)); } else if (t == DataTypes.LongType) { col.putLongs(0, capacity, row.getLong(fieldIdx)); } else if (t == DataTypes.FloatType) { col.putFloats(0, capacity, row.getFloat(fieldIdx)); } else if (t == DataTypes.DoubleType) { col.putDoubles(0, capacity, row.getDouble(fieldIdx)); } else if (t == DataTypes.StringType) { UTF8String v = row.getUTF8String(fieldIdx); byte[] bytes = v.getBytes(); for (int i = 0; i < capacity; i++) { Decimal d = row.getDecimal(fieldIdx, dt.precision(), dt.scale()); if (dt.precision() <= Decimal.MAX_INT_DIGITS()) { col.putInts(0, capacity, (int)d.toUnscaledLong()); CalendarInterval c = (CalendarInterval)row.get(fieldIdx, t); col.getChild(0).putInts(0, capacity, c.months); col.getChild(1).putLongs(0, capacity, c.microseconds);
@Override public void write(InternalRow row, Encoder encoder) throws IOException { for (int i = 0; i < types.length; i += 1) { if (row.isNullAt(i)) { writers[i].write(null, encoder); } else { write(row, i, writers[i], encoder); } } }
@SuppressWarnings("unchecked") private <T> void write(InternalRow row, int pos, ValueWriter<T> writer, Encoder encoder) throws IOException { writer.write((T) row.get(pos, types[pos]), encoder); } }
if (partitionValues.numFields() > 0) { int partitionIdx = requiredFields.length; for (int i = 0; i < partitionValues.numFields(); i++) { ColumnVectorUtils.populate(columnVectors[i + partitionIdx], partitionValues, i); columnVectors[i + partitionIdx].setIsConstant(); if (partitionValues.numFields() > 0) { int partitionIdx = requiredFields.length; for (int i = 0; i < partitionValues.numFields(); i++) { DataType dt = partitionSchema.fields()[i].dataType(); OnHeapColumnVector partitionCol = new OnHeapColumnVector(capacity, dt);
if (row.isNullAt(fieldIdx)) { col.putNulls(0, capacity); } else { if (t == DataTypes.BooleanType) { col.putBooleans(0, capacity, row.getBoolean(fieldIdx)); } else if (t == DataTypes.ByteType) { col.putBytes(0, capacity, row.getByte(fieldIdx)); } else if (t == DataTypes.ShortType) { col.putShorts(0, capacity, row.getShort(fieldIdx)); } else if (t == DataTypes.IntegerType) { col.putInts(0, capacity, row.getInt(fieldIdx)); } else if (t == DataTypes.LongType) { col.putLongs(0, capacity, row.getLong(fieldIdx)); } else if (t == DataTypes.FloatType) { col.putFloats(0, capacity, row.getFloat(fieldIdx)); } else if (t == DataTypes.DoubleType) { col.putDoubles(0, capacity, row.getDouble(fieldIdx)); } else if (t == DataTypes.StringType) { UTF8String v = row.getUTF8String(fieldIdx); byte[] bytes = v.getBytes(); for (int i = 0; i < capacity; i++) { Decimal d = row.getDecimal(fieldIdx, dt.precision(), dt.scale()); if (dt.precision() <= Decimal.MAX_INT_DIGITS()) { col.putInts(0, capacity, (int)d.toUnscaledLong()); CalendarInterval c = (CalendarInterval)row.get(fieldIdx, t); col.getChild(0).putInts(0, capacity, c.months); col.getChild(1).putLongs(0, capacity, c.microseconds);