@Test public void testCombineResultSet() { Row row1 = new Row(); row1.setValues(new Value[] {textValue1, booleanValue1, numberValue1}); Row row2 = new Row(); row2.setValues(new Value[] {textValue2, booleanValue2, numberValue2}); Row row3 = new Row(); row3.setValues(new Value[] {textValue3, booleanValue3, numberValue3}); ResultSet resultSet1 = new ResultSet(); resultSet1.setColumnTypes(new ColumnType[] {column1, column2, column3}); resultSet1.setRows(new Row[] {row1, row2}); ResultSet resultSet2 = new ResultSet(); resultSet2.setColumnTypes(new ColumnType[] {column1, column2, column3}); resultSet2.setRows(new Row[] {row3}); ResultSet combinedResultSet = Pql.combineResultSets(resultSet1, resultSet2); assertEquals(3, combinedResultSet.getRows().length); assertArrayEquals( new ColumnType[] {column1, column2, column3}, combinedResultSet.getColumnTypes()); assertArrayEquals( new Value[] {textValue1, booleanValue1, numberValue1}, combinedResultSet.getRows()[0].getValues()); assertArrayEquals( new Value[] {textValue2, booleanValue2, numberValue2}, combinedResultSet.getRows()[1].getValues()); assertArrayEquals( new Value[] {textValue3, booleanValue3, numberValue3}, combinedResultSet.getRows()[2].getValues()); }
public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { @Override public String apply(ColumnType input) { return input.getLabelName(); } }; List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString); List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString); if (!firstColumns.equals(secondColumns)) { throw new IllegalArgumentException( String.format( "First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns))); } List<Row> combinedRows = Lists.newArrayList(first.getRows()); if (second.getRows() != null) { Collections.addAll(combinedRows, second.getRows()); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.setColumnTypes(first.getColumnTypes()); combinedResultSet.setRows(combinedRows.toArray(new Row[] {})); return combinedResultSet; }
Pql { public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { @Override public String apply(ColumnType input) { return input.getLabelName(); } }; List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString); List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString); if (!firstColumns.equals(secondColumns)) { throw new IllegalArgumentException( String.format( "First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns))); } List<Row> combinedRows = Lists.newArrayList(first.getRows()); if (second.getRows() != null) { Collections.addAll(combinedRows, second.getRows()); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.setColumnTypes(first.getColumnTypes()); combinedResultSet.setRows(combinedRows.toArray(new Row[] {})); return combinedResultSet; } }
Pql { public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { @Override public String apply(ColumnType input) { return input.getLabelName(); } }; List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString); List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString); if (!firstColumns.equals(secondColumns)) { throw new IllegalArgumentException( String.format( "First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns))); } List<Row> combinedRows = Lists.newArrayList(first.getRows()); if (second.getRows() != null) { Collections.addAll(combinedRows, second.getRows()); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.setColumnTypes(first.getColumnTypes()); combinedResultSet.setRows(combinedRows.toArray(new Row[] {})); return combinedResultSet; } private  Pql(); }
Pql { public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { @Override public String apply(ColumnType input) { return input.getLabelName(); } }; List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString); List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString); if (!firstColumns.equals(secondColumns)) { throw new IllegalArgumentException( String.format( "First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns))); } List<Row> combinedRows = Lists.newArrayList(first.getRows()); if (second.getRows() != null) { Collections.addAll(combinedRows, second.getRows()); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.setColumnTypes(first.getColumnTypes()); combinedResultSet.setRows(combinedRows.toArray(new Row[] {})); return combinedResultSet; } private  Pql(); static Value createValue(Object value); static String toString(Value value); static Object getApiValue(Value value); static Object getNativeValue(Value value); static Object getCsvValue(Value value); static List<String[]> resultSetToStringArrayList(ResultSet resultSet); static String resultSetToString(ResultSet resultSet); static List<String> getColumnLabels(ResultSet resultSet); static List<String> getRowStringValues(Row row); static ResultSet combineResultSets(ResultSet first, ResultSet second); }
Pql { public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { @Override public String apply(ColumnType input) { return input.getLabelName(); } }; List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString); List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString); if (!firstColumns.equals(secondColumns)) { throw new IllegalArgumentException( String.format( "First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns))); } List<Row> combinedRows = Lists.newArrayList(first.getRows()); if (second.getRows() != null) { Collections.addAll(combinedRows, second.getRows()); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.setColumnTypes(first.getColumnTypes()); combinedResultSet.setRows(combinedRows.toArray(new Row[] {})); return combinedResultSet; } private  Pql(); static Value createValue(Object value); static String toString(Value value); static Object getApiValue(Value value); static Object getNativeValue(Value value); static Object getCsvValue(Value value); static List<String[]> resultSetToStringArrayList(ResultSet resultSet); static String resultSetToString(ResultSet resultSet); static List<String> getColumnLabels(ResultSet resultSet); static List<String> getRowStringValues(Row row); static ResultSet combineResultSets(ResultSet first, ResultSet second);  }