Github user prashantkommireddi commented on a diff in the pull request: https://github.com/apache/incubator-phoenix/pull/22#discussion_r10853790 --- Diff: phoenix-pig/src/main/java/org/apache/phoenix/pig/TypeUtil.java --- @@ -185,5 +194,85 @@ public static Object castBytes(Object o, PDataType targetPhoenixType) throws IOE return o; } } + + public static Tuple transformToTuple(final PhoenixRecord record, final List<? extends ColumnProjector> projectedColumns) throws IOException { + + List<Object> columnValues = record.getValues(); + if(columnValues == null || columnValues.size() == 0 || projectedColumns == null || projectedColumns.size() != columnValues.size()) { + return null; + } + int columns = columnValues.size(); + Tuple _tuple = TupleFactory.getInstance().newTuple(columns); + try { + for (int i = 0 ; i < columns ; i++) { + ColumnProjector projector = projectedColumns.get(i); + Integer type = projector.getExpression().getDataType().getSqlType(); + Object obj = columnValues.get(i); + + if (obj == null) { + _tuple.set(i, null); + continue; + } + + switch (type) { + case Types.NULL: + _tuple.set(i, null); + break; + case Types.BIGINT: + if (obj instanceof BigDecimal) { + Long longValue = DataType.toLong(obj, DataType.BIGINTEGER); + _tuple.set(i, longValue); + break; + } + case Types.INTEGER: + case Types.TINYINT: + case Types.SMALLINT: + _tuple.set(i, new Long((Long) obj).longValue()); + break; + case Types.DECIMAL: + case Types.NUMERIC: + case Types.REAL: + if (obj instanceof BigDecimal) { + _tuple.set(i, new Double(((BigDecimal) obj).doubleValue())); + break; + } + case Types.FLOAT: + case Types.DOUBLE: + _tuple.set(i, new Double((Double)obj).doubleValue()); + break; + case Types.BINARY: + case Types.LONGVARBINARY: + case Types.VARBINARY: + _tuple.set(i, new DataByteArray((byte [])obj)); + break; + case Types.BIT: + case Types.BOOLEAN: + _tuple.set(i, Boolean.valueOf((Boolean) obj)); + break; + case Types.CHAR: + case Types.LONGNVARCHAR: + case Types.LONGVARCHAR: + case Types.NCHAR: + case Types.NVARCHAR: + case Types.VARCHAR: + _tuple.set(i, String.valueOf(obj)); + break; + case Types.DATE: + case Types.TIME: + case Types.TIMESTAMP: + _tuple.set(i,DataType.toDateTime(obj, DataType.DATETIME)); + break; + default: + throw new IOException("Unknown type value " + type); + } + } + } catch( Exception ex) { + final String errorMsg = String.format(" Error transforming PhoenixRecord to Tuple [%s] ", ex.getMessage()); + ex.printStackTrace(); --- End diff -- Please remove this.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---