@Test public void testFillOneGPDBWritableField() throws Exception { RequestContext context = new RequestContext(); addColumn(context, 0, DataType.INTEGER, "col0"); BridgeOutputBuilder builder = makeBuilder(context); output = builder.makeGPDBWritableOutput(); OneField unSupportedField = new OneField(UN_SUPPORTED_TYPE, (byte) 0); try { builder.fillOneGPDBWritableField(unSupportedField, 0); fail("Unsupported data type should throw exception"); } catch (UnsupportedOperationException e) { assertEquals(e.getMessage(), "Byte is not supported for GPDB conversion"); } }
void fillOneGPDBWritableField(OneField oneField, int colIdx) throws BadRecordException { int type = oneField.type; Object val = oneField.val; GPDBWritable gpdbOutput = (GPDBWritable) output; try { switch (DataType.get(type)) { case INTEGER: gpdbOutput.setInt(colIdx, (Integer) val); break; case FLOAT8: gpdbOutput.setDouble(colIdx, (Double) val); break; case REAL: gpdbOutput.setFloat(colIdx, (Float) val); break; case BIGINT: gpdbOutput.setLong(colIdx, (Long) val); break; case SMALLINT: gpdbOutput.setShort(colIdx, (Short) val); break; case BOOLEAN: gpdbOutput.setBoolean(colIdx, (Boolean) val); break; case BYTEA: byte[] bts = null; if (val != null) { int length = Array.getLength(val); bts = new byte[length]; for (int j = 0; j < length; j++) { bts[j] = Array.getByte(val, j); } } gpdbOutput.setBytes(colIdx, bts); break; case VARCHAR: case BPCHAR: case TEXT: case NUMERIC: case TIMESTAMP: case DATE: gpdbOutput.setString(colIdx, ObjectUtils.toString(val, null)); break; default: String valClassName = (val != null) ? val.getClass().getSimpleName() : null; throw new UnsupportedOperationException(valClassName + " is not supported for GPDB conversion"); } } catch (GPDBWritable.TypeMismatchException e) { throw new BadRecordException(e); } }
BridgeOutputBuilder { void fillOneGPDBWritableField(OneField oneField, int colIdx) throws BadRecordException { int type = oneField.type; Object val = oneField.val; GPDBWritable gpdbOutput = (GPDBWritable) output; try { switch (DataType.get(type)) { case INTEGER: gpdbOutput.setInt(colIdx, (Integer) val); break; case FLOAT8: gpdbOutput.setDouble(colIdx, (Double) val); break; case REAL: gpdbOutput.setFloat(colIdx, (Float) val); break; case BIGINT: gpdbOutput.setLong(colIdx, (Long) val); break; case SMALLINT: gpdbOutput.setShort(colIdx, (Short) val); break; case BOOLEAN: gpdbOutput.setBoolean(colIdx, (Boolean) val); break; case BYTEA: byte[] bts = null; if (val != null) { int length = Array.getLength(val); bts = new byte[length]; for (int j = 0; j < length; j++) { bts[j] = Array.getByte(val, j); } } gpdbOutput.setBytes(colIdx, bts); break; case VARCHAR: case BPCHAR: case TEXT: case NUMERIC: case TIMESTAMP: case DATE: gpdbOutput.setString(colIdx, ObjectUtils.toString(val, null)); break; default: String valClassName = (val != null) ? val.getClass().getSimpleName() : null; throw new UnsupportedOperationException(valClassName + " is not supported for GPDB conversion"); } } catch (GPDBWritable.TypeMismatchException e) { throw new BadRecordException(e); } } }
BridgeOutputBuilder { void fillOneGPDBWritableField(OneField oneField, int colIdx) throws BadRecordException { int type = oneField.type; Object val = oneField.val; GPDBWritable gpdbOutput = (GPDBWritable) output; try { switch (DataType.get(type)) { case INTEGER: gpdbOutput.setInt(colIdx, (Integer) val); break; case FLOAT8: gpdbOutput.setDouble(colIdx, (Double) val); break; case REAL: gpdbOutput.setFloat(colIdx, (Float) val); break; case BIGINT: gpdbOutput.setLong(colIdx, (Long) val); break; case SMALLINT: gpdbOutput.setShort(colIdx, (Short) val); break; case BOOLEAN: gpdbOutput.setBoolean(colIdx, (Boolean) val); break; case BYTEA: byte[] bts = null; if (val != null) { int length = Array.getLength(val); bts = new byte[length]; for (int j = 0; j < length; j++) { bts[j] = Array.getByte(val, j); } } gpdbOutput.setBytes(colIdx, bts); break; case VARCHAR: case BPCHAR: case TEXT: case NUMERIC: case TIMESTAMP: case DATE: gpdbOutput.setString(colIdx, ObjectUtils.toString(val, null)); break; default: String valClassName = (val != null) ? val.getClass().getSimpleName() : null; throw new UnsupportedOperationException(valClassName + " is not supported for GPDB conversion"); } } catch (GPDBWritable.TypeMismatchException e) { throw new BadRecordException(e); } } BridgeOutputBuilder(RequestContext context); }
BridgeOutputBuilder { void fillOneGPDBWritableField(OneField oneField, int colIdx) throws BadRecordException { int type = oneField.type; Object val = oneField.val; GPDBWritable gpdbOutput = (GPDBWritable) output; try { switch (DataType.get(type)) { case INTEGER: gpdbOutput.setInt(colIdx, (Integer) val); break; case FLOAT8: gpdbOutput.setDouble(colIdx, (Double) val); break; case REAL: gpdbOutput.setFloat(colIdx, (Float) val); break; case BIGINT: gpdbOutput.setLong(colIdx, (Long) val); break; case SMALLINT: gpdbOutput.setShort(colIdx, (Short) val); break; case BOOLEAN: gpdbOutput.setBoolean(colIdx, (Boolean) val); break; case BYTEA: byte[] bts = null; if (val != null) { int length = Array.getLength(val); bts = new byte[length]; for (int j = 0; j < length; j++) { bts[j] = Array.getByte(val, j); } } gpdbOutput.setBytes(colIdx, bts); break; case VARCHAR: case BPCHAR: case TEXT: case NUMERIC: case TIMESTAMP: case DATE: gpdbOutput.setString(colIdx, ObjectUtils.toString(val, null)); break; default: String valClassName = (val != null) ? val.getClass().getSimpleName() : null; throw new UnsupportedOperationException(valClassName + " is not supported for GPDB conversion"); } } catch (GPDBWritable.TypeMismatchException e) { throw new BadRecordException(e); } } BridgeOutputBuilder(RequestContext context); Writable getErrorOutput(Exception ex); LinkedList<Writable> makeOutput(List<OneField> recFields); LinkedList<Writable> makeVectorizedOutput(List<List<OneField>> recordsBatch); Writable getPartialLine(); }
BridgeOutputBuilder { void fillOneGPDBWritableField(OneField oneField, int colIdx) throws BadRecordException { int type = oneField.type; Object val = oneField.val; GPDBWritable gpdbOutput = (GPDBWritable) output; try { switch (DataType.get(type)) { case INTEGER: gpdbOutput.setInt(colIdx, (Integer) val); break; case FLOAT8: gpdbOutput.setDouble(colIdx, (Double) val); break; case REAL: gpdbOutput.setFloat(colIdx, (Float) val); break; case BIGINT: gpdbOutput.setLong(colIdx, (Long) val); break; case SMALLINT: gpdbOutput.setShort(colIdx, (Short) val); break; case BOOLEAN: gpdbOutput.setBoolean(colIdx, (Boolean) val); break; case BYTEA: byte[] bts = null; if (val != null) { int length = Array.getLength(val); bts = new byte[length]; for (int j = 0; j < length; j++) { bts[j] = Array.getByte(val, j); } } gpdbOutput.setBytes(colIdx, bts); break; case VARCHAR: case BPCHAR: case TEXT: case NUMERIC: case TIMESTAMP: case DATE: gpdbOutput.setString(colIdx, ObjectUtils.toString(val, null)); break; default: String valClassName = (val != null) ? val.getClass().getSimpleName() : null; throw new UnsupportedOperationException(valClassName + " is not supported for GPDB conversion"); } } catch (GPDBWritable.TypeMismatchException e) { throw new BadRecordException(e); } } BridgeOutputBuilder(RequestContext context); Writable getErrorOutput(Exception ex); LinkedList<Writable> makeOutput(List<OneField> recFields); LinkedList<Writable> makeVectorizedOutput(List<List<OneField>> recordsBatch); Writable getPartialLine();  }