public abstract class RewriteSemanticAnalyzer extends CalcitePlanner
SemanticAnalyzer that just handles
update, delete and merge statements. It works by rewriting the updates and deletes into insert
statements (since they are actually inserts) and then doing some patch up to make them work as
updates and deletes instead.| Modifier and Type | Class and Description |
|---|---|
protected static class |
RewriteSemanticAnalyzer.ColumnAppender |
protected static class |
RewriteSemanticAnalyzer.NativeAcidColumnAppender |
protected static class |
RewriteSemanticAnalyzer.NonNativeAcidColumnAppender |
protected static class |
RewriteSemanticAnalyzer.ReparseResult |
CalcitePlanner.ASTSearcher, CalcitePlanner.CalcitePlannerAction, CalcitePlanner.InputContext, CalcitePlanner.PreCboCtxSemanticAnalyzer.GenericUDAFInfo, SemanticAnalyzer.MaterializationRebuildModeBaseSemanticAnalyzer.AnalyzeRewriteContext, BaseSemanticAnalyzer.TableSpec| Modifier and Type | Field and Description |
|---|---|
static String |
DELETE_PREFIX |
protected static String |
INDENT |
protected static org.slf4j.Logger |
LOG |
static String |
SUB_QUERY_ALIAS |
protected boolean |
useSuper |
aliasToCTEs, analyzeRewrite, ast, autogenColAliasPrfxLbl, createVwDesc, defaultJoinMerge, disableJoinMerge, DUMMY_DATABASE, DUMMY_TABLE, forViewCreation, mvRebuildDbName, mvRebuildMode, mvRebuildName, opParseCtx, originalResultSchema, prunedPartitions, resultSchema, SUBQUERY_TAG_1, SUBQUERY_TAG_2, topOps, topOpsCopy, unparseTranslator, VALUES_TMP_TABLE_NAME_PREFIX, viewSelectacidFileSinks, cacheUsage, cContext, columnAccessInfo, conf, console, ctx, db, fetchTask, idToTableNameMap, inputs, linfo, outputs, prepareQuery, queryProperties, queryState, rootTasks, STATIC_LOG, tableAccessInfo, transactionalInQuery, txnManager, updateColumnAccessInfo| Modifier and Type | Method and Description |
|---|---|
protected void |
addColsToSelect(List<org.apache.hadoop.hive.metastore.api.FieldSchema> partCols,
StringBuilder rewrittenQueryStr)
Append list of partition columns to Insert statement, i.e.
|
protected void |
addColsToSelect(List<org.apache.hadoop.hive.metastore.api.FieldSchema> cols,
StringBuilder rewrittenQueryStr,
ASTNode target)
Append list of columns to rewritten statement.
|
protected void |
addColsToSelect(List<org.apache.hadoop.hive.metastore.api.FieldSchema> cols,
StringBuilder rewrittenQueryStr,
String alias)
Append list of columns to rewritten statement.
|
protected void |
addPartitionColsAsValues(List<org.apache.hadoop.hive.metastore.api.FieldSchema> partCols,
String alias,
List<String> values) |
protected abstract void |
analyze(ASTNode tree,
Table table,
ASTNode tableName) |
void |
analyzeInternal(ASTNode tree) |
void |
analyzeRewrittenTree(ASTNode rewrittenTree,
Context rewrittenCtx) |
protected void |
appendInsertBranch(StringBuilder rewrittenQueryStr,
String hintStr,
List<String> values) |
protected void |
appendSortBy(StringBuilder rewrittenQueryStr,
List<String> keys) |
protected void |
appendTarget(StringBuilder rewrittenQueryStr,
ASTNode target,
String targetName) |
protected void |
checkValidSetClauseTarget(ASTNode colName,
Table targetTable)
Assert that we are not asked to update a bucketing column or partition column.
|
protected Map<String,ASTNode> |
collectSetColumnsAndExpressions(ASTNode setClause,
Set<String> setRCols,
Table targetTable) |
protected StringBuilder |
createRewrittenQueryStrBuilder() |
protected ASTNode |
findLHSofAssignment(ASTNode assignment) |
protected RewriteSemanticAnalyzer.ColumnAppender |
getColumnAppender(String subQueryAlias) |
protected String |
getMatchedText(ASTNode n)
This allows us to take an arbitrary ASTNode and turn it back into SQL that produced it without
needing to understand what it is (except for QuotedIdentifiers).
|
protected String |
getSimpleTableName(ASTNode n)
Returns the table name to use in the generated query preserving original quotes/escapes if any.
|
protected static Table |
getTable(ASTNode tabRef,
Hive db,
boolean throwException) |
protected abstract ASTNode |
getTargetTableNode(ASTNode tree) |
protected boolean |
isAliased(ASTNode n) |
protected void |
markReadEntityForUpdate()
Walk through all our inputs and set them to note that this read is part of an update or a delete.
|
protected RewriteSemanticAnalyzer.ReparseResult |
parseRewrittenQuery(StringBuilder rewrittenQueryStr,
String originalQuery)
Parse the newly generated SQL statement to get a new AST.
|
protected void |
patchProjectionForUpdate(ASTNode insertBranch,
Map<Integer,ASTNode> setColExprs) |
protected void |
setUpAccessControlInfoForUpdate(Table mTable,
Map<String,ASTNode> setCols)
For updates, we need to set the column access info so that it contains information on
the columns we are updating.
|
protected void |
updateOutputs(Table targetTable)
SemanticAnalyzer will generate a WriteEntity for the target table since it doesn't know/check
if the read and write are of the same table in "insert ...
|
protected void |
validateTargetTable(Table mTable)
Assert it supports Acid write.
|
createPlanner, createPlannerAction, fixUpAfterCbo, genLogicalPlan, getOptimizedSql, getTableObjectByName, resetCalciteConfiguration, warmupaddPartitionColsToInsert, addPartitionColsToInsert, allowOutputMultipleTimes, analyzeCreateView, compilePlan, enableColumnStatsCollecting, executeUnparseTranlations, forViewCreation, generateErrorMessage, genExprNodeDesc, genFileSinkPlan, getAcidAnalyzeTable, getAliasId, getAllInputs, getAllOutputs, getAllRootTasks, getColNameToDefaultValueMap, getColumnInternalName, getDefaultConstraints, getDummyTable, getFullTableNameForSQL, getGenericUDAFEvaluator, getGenericUDAFEvaluator2, getGenericUDAFInfo, getGenericUDAFInfo2, getInvalidAutomaticRewritingMaterializationReason, getInvalidResultCacheReason, getLoadFileWork, getLoadTableWork, getOpContext, getOriginalResultSchema, getParseContext, getQB, getResultSchema, getSinkOp, getTableObjectByName, getTargetTable, getTopOps, getViewAliasToInput, groupByDescModeToUDAFMode, hasGroupBySibling, init, isConstantParameterInAggregationParameters, isInsertInto, isSelectDistinct, isValidAutomaticRewritingMaterialization, isValidQueryCaching, parseSelect, processNoScanCommand, processTableColumnNames, reset, rewriteGroupingFunctionAST, saveViewDefinition, setAST, setBit, setInvalidAutomaticRewritingMaterializationReason, setInvalidResultCacheReason, setLoadFileWork, setLoadTableWork, startAnalysis, translateFieldDesc, updating, validateaddPropertyReadEntry, analyze, analyzeStoredAdDirs, charSetString, checkColumnName, constructListBucketingCtx, createFetchTask, createHiveDB, endAnalysis, escapeSQLString, findTabRefIdxs, getAcidDdlDesc, getAcidFileSinks, getAutoCommitValue, getCacheUsage, getCboInfo, getColumnAccessInfo, getColumnNames, getColumnNamesOrder, getColumns, getColumns, getColumns, getCtx, getDatabase, getDatabase, getDataConnector, getDataConnector, getDb, getDbTableNamePair, getFetchTask, getIdToTableNameMap, getInputs, getLineageInfo, getOutputs, getPartitionSpecs, getPartSpec, getProps, getQualifiedTableName, getQualifiedTableName, getQueryProperties, getQueryState, getRootTasks, getSimpleTableNameBase, getTable, getTable, getTable, getTable, getTable, getTable, getTableAccessInfo, getTableAlias, getTxnMgr, getTypeStringFromAST, getUnescapedName, getUnescapedName, getUnescapedUnqualifiedTableName, getUpdateColumnAccessInfo, getValidatedPartSpec, hasTransactionalInQuery, initCtx, isPrepareQuery, isValidPrefixSpec, raiseWrongType, readProps, setAutoCommitValue, setCacheUsage, setColumnAccessInfo, setFetchTask, setLineageInfo, setTableAccessInfo, setUpdateColumnAccessInfo, skipAuthorization, stripQuotes, toReadEntity, toReadEntity, toReadEntity, toWriteEntity, toWriteEntity, toWriteEntity, tryQualifyPath, unescapeIdentifier, unescapeSQLString, validatePartColumnType, validatePartSpec, validateUnsupportedPartitionClauseprotected static final org.slf4j.Logger LOG
protected boolean useSuper
protected static final String INDENT
public static final String DELETE_PREFIX
public static final String SUB_QUERY_ALIAS
public void analyzeInternal(ASTNode tree) throws SemanticException
analyzeInternal in class CalcitePlannerSemanticExceptionprotected abstract void analyze(ASTNode tree, Table table, ASTNode tableName) throws SemanticException
SemanticExceptionpublic void analyzeRewrittenTree(ASTNode rewrittenTree, Context rewrittenCtx) throws SemanticException
SemanticExceptionprotected void addColsToSelect(List<org.apache.hadoop.hive.metastore.api.FieldSchema> partCols, StringBuilder rewrittenQueryStr) throws SemanticException
SemanticExceptionprotected void addColsToSelect(List<org.apache.hadoop.hive.metastore.api.FieldSchema> cols, StringBuilder rewrittenQueryStr, ASTNode target) throws SemanticException
SemanticExceptionprotected void addColsToSelect(List<org.apache.hadoop.hive.metastore.api.FieldSchema> cols, StringBuilder rewrittenQueryStr, String alias)
protected void addPartitionColsAsValues(List<org.apache.hadoop.hive.metastore.api.FieldSchema> partCols, String alias, List<String> values)
protected void checkValidSetClauseTarget(ASTNode colName, Table targetTable) throws SemanticException
colName - it's the A in "SET A = B"SemanticExceptionprotected Map<String,ASTNode> collectSetColumnsAndExpressions(ASTNode setClause, Set<String> setRCols, Table targetTable) throws SemanticException
SemanticExceptionprotected static Table getTable(ASTNode tabRef, Hive db, boolean throwException) throws SemanticException
throwException - if false, return null if table doesn't exist, else throwSemanticExceptionprotected void markReadEntityForUpdate()
protected void setUpAccessControlInfoForUpdate(Table mTable, Map<String,ASTNode> setCols)
protected RewriteSemanticAnalyzer.ReparseResult parseRewrittenQuery(StringBuilder rewrittenQueryStr, String originalQuery) throws SemanticException
SemanticExceptionprotected void validateTargetTable(Table mTable) throws SemanticException
SemanticExceptionprotected void updateOutputs(Table targetTable)
protected String getSimpleTableName(ASTNode n) throws SemanticException
SemanticExceptionSemanticAnalyzer.getFullTableNameForSQL(ASTNode)protected void patchProjectionForUpdate(ASTNode insertBranch, Map<Integer,ASTNode> setColExprs)
protected StringBuilder createRewrittenQueryStrBuilder()
protected void appendTarget(StringBuilder rewrittenQueryStr, ASTNode target, String targetName)
protected boolean isAliased(ASTNode n)
protected void appendInsertBranch(StringBuilder rewrittenQueryStr, String hintStr, List<String> values)
protected void appendSortBy(StringBuilder rewrittenQueryStr, List<String> keys)
protected String getMatchedText(ASTNode n)
protected RewriteSemanticAnalyzer.ColumnAppender getColumnAppender(String subQueryAlias)
Copyright © 2022 The Apache Software Foundation. All rights reserved.