in flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/parse/HiveParserDDLSemanticAnalyzer.java [766:875]
private Operation convertCreateView(HiveParserASTNode ast) throws SemanticException {
ObjectIdentifier tableIdentifier =
HiveParserBaseSemanticAnalyzer.getObjectIdentifier(
catalogRegistry, (HiveParserASTNode) ast.getChild(0));
String[] qualTabName =
new String[] {tableIdentifier.getDatabaseName(), tableIdentifier.getObjectName()};
String dbDotTable = HiveParserBaseSemanticAnalyzer.getDotName(qualTabName);
List<FieldSchema> cols = null;
boolean ifNotExists = false;
boolean isAlterViewAs = false;
String comment = null;
HiveParserASTNode selectStmt = null;
Map<String, String> tblProps = null;
boolean isMaterialized =
ast.getToken().getType() == HiveASTParser.TOK_CREATE_MATERIALIZED_VIEW;
if (isMaterialized) {
handleUnsupportedOperation("MATERIALIZED VIEW is not supported");
}
HiveParserStorageFormat storageFormat = new HiveParserStorageFormat(conf);
LOG.info("Creating view " + dbDotTable + " position=" + ast.getCharPositionInLine());
int numCh = ast.getChildCount();
for (int num = 1; num < numCh; num++) {
HiveParserASTNode child = (HiveParserASTNode) ast.getChild(num);
if (storageFormat.fillStorageFormat(child)) {
handleUnsupportedOperation("FILE FORMAT for view is not supported");
}
switch (child.getToken().getType()) {
case HiveASTParser.TOK_IFNOTEXISTS:
ifNotExists = true;
break;
case HiveASTParser.TOK_REWRITE_ENABLED:
handleUnsupportedOperation("MATERIALIZED VIEW REWRITE is not supported");
break;
case HiveASTParser.TOK_ORREPLACE:
handleUnsupportedOperation("CREATE OR REPLACE VIEW is not supported");
break;
case HiveASTParser.TOK_QUERY:
selectStmt = child;
break;
case HiveASTParser.TOK_TABCOLNAME:
cols = HiveParserBaseSemanticAnalyzer.getColumns(child);
break;
case HiveASTParser.TOK_TABLECOMMENT:
comment =
HiveParserBaseSemanticAnalyzer.unescapeSQLString(
child.getChild(0).getText());
break;
case HiveASTParser.TOK_TABLEPROPERTIES:
tblProps = getProps((HiveParserASTNode) child.getChild(0));
break;
case HiveASTParser.TOK_TABLEROWFORMAT:
handleUnsupportedOperation("ROW FORMAT for view is not supported");
break;
case HiveASTParser.TOK_TABLESERIALIZER:
handleUnsupportedOperation("SERDE for view is not supported");
break;
case HiveASTParser.TOK_TABLELOCATION:
handleUnsupportedOperation("LOCATION for view is not supported");
break;
case HiveASTParser.TOK_VIEWPARTCOLS:
handleUnsupportedOperation("PARTITION COLUMN for view is not supported");
break;
default:
throw new ValidationException(
"Unknown AST node for CREATE/ALTER VIEW: " + child);
}
}
if (ast.getToken().getType() == HiveASTParser.TOK_ALTERVIEW
&& ast.getChild(1).getType() == HiveASTParser.TOK_QUERY) {
isAlterViewAs = true;
}
queryState.setCommandType(HiveOperation.CREATEVIEW);
HiveParserCreateViewInfo createViewInfo =
new HiveParserCreateViewInfo(dbDotTable, cols, selectStmt);
hiveParser.analyzeCreateView(createViewInfo, context, queryState);
ObjectIdentifier viewIdentifier = parseObjectIdentifier(createViewInfo.getCompoundName());
Schema schema =
HiveTableUtil.createSchema(
createViewInfo.getSchema(),
Collections.emptyList(),
Collections.emptySet(),
null);
Map<String, String> props = new HashMap<>();
if (isAlterViewAs) {
ResolvedCatalogBaseTable<?> baseTable = getResolvedCatalogBaseTable(viewIdentifier);
props.putAll(baseTable.getOptions());
comment = baseTable.getComment();
} else {
if (tblProps != null) {
props.putAll(tblProps);
}
}
CatalogView catalogView =
CatalogView.of(
schema,
comment,
createViewInfo.getOriginalText(),
createViewInfo.getExpandedText(),
props);
if (isAlterViewAs) {
return new AlterViewAsOperation(viewIdentifier, catalogView);
} else {
return new CreateViewOperation(viewIdentifier, catalogView, ifNotExists, false);
}
}