use of org.apache.phoenix.parse.HintNode in project phoenix by apache.
the class QueryUtil method constructUpsertStatement.
/**
* Generate an upsert statement based on a list of {@code ColumnInfo}s with parameter markers. The list of
* {@code ColumnInfo}s must contain at least one element.
*
* @param tableName name of the table for which the upsert statement is to be created
* @param columns list of columns to be included in the upsert statement
* @param hint hint to be added to the UPSERT statement.
* @return the created {@code UPSERT} statement
*/
public static String constructUpsertStatement(String tableName, List<String> columns, Hint hint) {
if (columns.isEmpty()) {
throw new IllegalArgumentException("At least one column must be provided for upserts");
}
String hintStr = "";
if (hint != null) {
final HintNode node = new HintNode(hint.name());
hintStr = node.toString();
}
List<String> parameterList = Lists.newArrayList();
for (int i = 0; i < columns.size(); i++) {
parameterList.add("?");
}
return String.format("UPSERT %s INTO %s (%s) VALUES (%s)", hintStr, tableName, Joiner.on(", ").join(Iterables.transform(columns, new Function<String, String>() {
@Nullable
@Override
public String apply(@Nullable String columnName) {
return getEscapedFullColumnName(columnName);
}
})), Joiner.on(", ").join(parameterList));
}
Aggregations