use of org.apache.flink.sql.parser.SqlProperty in project flink by apache.
the class RichSqlHiveInsert method getPartKeyToSpec.
private static Map<SqlIdentifier, SqlProperty> getPartKeyToSpec(SqlNodeList staticSpec) {
Map<SqlIdentifier, SqlProperty> res = new HashMap<>();
if (staticSpec != null) {
for (SqlNode node : staticSpec) {
SqlProperty spec = (SqlProperty) node;
res.put(spec.getKey(), spec);
}
}
return res;
}
use of org.apache.flink.sql.parser.SqlProperty in project flink by apache.
the class RichSqlInsert method getStaticPartitionKVs.
/**
* Get static partition key value pair as strings.
*
* <p>For character literals we return the unquoted and unescaped values. For other types we use
* {@link SqlLiteral#toString()} to get the string format of the value literal. If the string
* format is not what you need, use {@link #getStaticPartitions()}.
*
* @return the mapping of column names to values of partition specifications, returns an empty
* map if there is no partition specifications.
*/
public LinkedHashMap<String, String> getStaticPartitionKVs() {
LinkedHashMap<String, String> ret = new LinkedHashMap<>();
if (this.staticPartitions.size() == 0) {
return ret;
}
for (SqlNode node : this.staticPartitions.getList()) {
SqlProperty sqlProperty = (SqlProperty) node;
Comparable comparable = SqlLiteral.value(sqlProperty.getValue());
String value = comparable instanceof NlsString ? ((NlsString) comparable).getValue() : comparable.toString();
ret.put(sqlProperty.getKey().getSimple(), value);
}
return ret;
}
use of org.apache.flink.sql.parser.SqlProperty in project flink by apache.
the class RichSqlHiveInsert method unparse.
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.startList(SqlWriter.FrameTypeEnum.SELECT);
String insertKeyword = "INSERT INTO";
if (isUpsert()) {
insertKeyword = "UPSERT INTO";
} else if (isOverwrite()) {
insertKeyword = "INSERT OVERWRITE";
}
writer.sep(insertKeyword);
final int opLeft = getOperator().getLeftPrec();
final int opRight = getOperator().getRightPrec();
getTargetTable().unparse(writer, opLeft, opRight);
if (getTargetColumnList() != null) {
getTargetColumnList().unparse(writer, opLeft, opRight);
}
writer.newlineAndIndent();
if (allPartKeys != null && allPartKeys.size() > 0) {
writer.keyword("PARTITION");
SqlWriter.Frame frame = writer.startList("(", ")");
for (SqlNode node : allPartKeys) {
writer.sep(",", false);
SqlIdentifier partKey = (SqlIdentifier) node;
SqlProperty spec = partKeyToSpec.get(partKey);
if (spec != null) {
spec.unparse(writer, leftPrec, rightPrec);
} else {
partKey.unparse(writer, leftPrec, rightPrec);
}
}
writer.endList(frame);
writer.newlineAndIndent();
}
getSource().unparse(writer, 0, 0);
}
Aggregations