QueryUtil { public static String constructUpsertStatement(String tableName, List<ColumnInfo> columnInfos) { if (columnInfos.isEmpty()) { throw new IllegalArgumentException("At least one column must be provided for upserts"); } List<String> parameterList = Lists.newArrayList(); for (int i = 0; i < columnInfos.size(); i++) { parameterList.add("?"); } return String.format( "UPSERT INTO %s (%s) VALUES (%s)", tableName, Joiner.on(", ").join( Iterables.transform( columnInfos, new Function<ColumnInfo, String>() { @Nullable @Override public String apply(@Nullable ColumnInfo columnInfo) { return getEscapedFullColumnName(columnInfo.getColumnName()); } })), Joiner.on(", ").join(parameterList)); } private  QueryUtil(); static String toSQL(CompareOp op); static String constructUpsertStatement(String tableName, List<ColumnInfo> columnInfos); static String constructGenericUpsertStatement(String tableName, int numColumns); static String constructSelectStatement(String fullTableName, List<ColumnInfo> columnInfos,final String conditions); static String getUrl(String server); static String getUrl(String server, long port); static String getExplainPlan(ResultSet rs); static String getExplainPlan(ResultIterator iterator); static Connection getConnection(Configuration conf); static Connection getConnection(Properties props, Configuration conf); static String getConnectionUrl(Properties props, Configuration conf); static String getViewStatement(String schemaName, String tableName, String where); static final int COLUMN_FAMILY_POSITION; static final int COLUMN_NAME_POSITION; static final int DATA_TYPE_POSITION; static final int DATA_TYPE_NAME_POSITION; }
@Test public void testConstructUpsertStatement_ColumnInfos() { assertEquals( "UPSERT INTO MYTAB (\"ID\", \"NAME\") VALUES (?, ?)", QueryUtil.constructUpsertStatement("MYTAB", ImmutableList.of(ID_COLUMN, NAME_COLUMN))); }
@Test(expected=IllegalArgumentException.class) public void testConstructUpsertStatement_ColumnInfos_NoColumns() { QueryUtil.constructUpsertStatement("MYTAB", ImmutableList.<ColumnInfo>of()); }