@Test public void testCombineResultSet_badColumns() { Row row1 = new Row(); row1.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue1)); Row row2 = new Row(); row2.getValues().addAll(Lists.newArrayList(textValue2, booleanValue2, numberValue2)); Row row3 = new Row(); row3.getValues().addAll(Lists.newArrayList(textValue3, booleanValue3)); ResultSet resultSet1 = new ResultSet(); resultSet1.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3)); resultSet1.getRows().addAll(Lists.newArrayList(row1, row2)); ResultSet resultSet2 = new ResultSet(); resultSet2.getColumnTypes().addAll(Lists.newArrayList(column1, column2)); resultSet2.getRows().addAll(Lists.newArrayList(row3)); thrown.expect(IllegalArgumentException.class); Pql.combineResultSets(resultSet1, resultSet2); }
public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { 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) { combinedRows.addAll(Lists.newArrayList(second.getRows())); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.getColumnTypes().addAll(first.getColumnTypes()); combinedResultSet.getRows().addAll(combinedRows); return combinedResultSet; }
Pql { public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { 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) { combinedRows.addAll(Lists.newArrayList(second.getRows())); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.getColumnTypes().addAll(first.getColumnTypes()); combinedResultSet.getRows().addAll(combinedRows); return combinedResultSet; } }
Pql { public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { 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) { combinedRows.addAll(Lists.newArrayList(second.getRows())); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.getColumnTypes().addAll(first.getColumnTypes()); combinedResultSet.getRows().addAll(combinedRows); return combinedResultSet; } private  Pql(); }
Pql { public static ResultSet combineResultSets(ResultSet first, ResultSet second) { Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() { 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) { combinedRows.addAll(Lists.newArrayList(second.getRows())); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.getColumnTypes().addAll(first.getColumnTypes()); combinedResultSet.getRows().addAll(combinedRows); 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>() { 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) { combinedRows.addAll(Lists.newArrayList(second.getRows())); } ResultSet combinedResultSet = new ResultSet(); combinedResultSet.getColumnTypes().addAll(first.getColumnTypes()); combinedResultSet.getRows().addAll(combinedRows); 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);  }