QueryUtil { public static String constructGenericUpsertStatement(String tableName, int numColumns) { if (numColumns == 0) { throw new IllegalArgumentException("At least one column must be provided for upserts"); } List<String> parameterList = Lists.newArrayListWithCapacity(numColumns); for (int i = 0; i < numColumns; i++) { parameterList.add("?"); } return String.format("UPSERT INTO %s VALUES (%s)", tableName, 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 testConstructGenericUpsertStatement() { assertEquals( "UPSERT INTO MYTAB VALUES (?, ?)", QueryUtil.constructGenericUpsertStatement("MYTAB", 2)); }
@Test(expected=IllegalArgumentException.class) public void testConstructGenericUpsertStatement_NoColumns() { QueryUtil.constructGenericUpsertStatement("MYTAB", 0); }