in flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserSemanticAnalyzer.java [2328:2396]
public Map<HiveParserASTNode, ExprNodeDesc> genAllExprNodeDesc(
HiveParserASTNode expr, HiveParserRowResolver input, HiveParserTypeCheckCtx tcCtx)
throws SemanticException {
// Create the walker and the rules dispatcher.
tcCtx.setUnparseTranslator(unparseTranslator);
Map<HiveParserASTNode, ExprNodeDesc> nodeOutputs =
HiveParserTypeCheckProcFactory.genExprNode(expr, tcCtx);
ExprNodeDesc desc = nodeOutputs.get(expr);
if (desc == null) {
String errMsg = tcCtx.getError();
if (errMsg == null) {
errMsg = "Error in parsing ";
}
throw new SemanticException(errMsg);
}
if (desc instanceof HiveParserExprNodeColumnListDesc) {
throw new SemanticException("TOK_ALLCOLREF is not supported in current context");
}
if (!unparseTranslator.isEnabled()) {
// Not creating a view, so no need to track view expansions.
return nodeOutputs;
}
Map<ExprNodeDesc, String> nodeToText = new HashMap<>();
List<HiveParserASTNode> fieldDescList = new ArrayList<>();
for (Map.Entry<HiveParserASTNode, ExprNodeDesc> entry : nodeOutputs.entrySet()) {
if (!(entry.getValue() instanceof ExprNodeColumnDesc)) {
// we need to translate the ExprNodeFieldDesc too, e.g., identifiers in
// struct<>.
if (entry.getValue() instanceof ExprNodeFieldDesc) {
fieldDescList.add(entry.getKey());
}
continue;
}
HiveParserASTNode node = entry.getKey();
ExprNodeColumnDesc columnDesc = (ExprNodeColumnDesc) entry.getValue();
if ((columnDesc.getTabAlias() == null) || (columnDesc.getTabAlias().length() == 0)) {
// These aren't real column refs; instead, they are special
// internal expressions used in the representation of aggregation.
continue;
}
String[] tmp = input.reverseLookup(columnDesc.getColumn());
// in subquery case, tmp may be from outside.
if (tmp[0] != null
&& columnDesc.getTabAlias() != null
&& !tmp[0].equals(columnDesc.getTabAlias())
&& tcCtx.getOuterRR() != null) {
tmp = tcCtx.getOuterRR().reverseLookup(columnDesc.getColumn());
}
StringBuilder replacementText = new StringBuilder();
replacementText.append(HiveUtils.unparseIdentifier(tmp[0], conf));
replacementText.append(".");
replacementText.append(HiveUtils.unparseIdentifier(tmp[1], conf));
nodeToText.put(columnDesc, replacementText.toString());
unparseTranslator.addTranslation(node, replacementText.toString());
}
for (HiveParserASTNode node : fieldDescList) {
Map<HiveParserASTNode, String> map = translateFieldDesc(node);
for (Entry<HiveParserASTNode, String> entry : map.entrySet()) {
unparseTranslator.addTranslation(entry.getKey(), entry.getValue());
}
}
return nodeOutputs;
}