You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "veghlaci05 (via GitHub)" <gi...@apache.org> on 2023/06/02 12:34:51 UTC
[GitHub] [hive] veghlaci05 commented on a diff in pull request #4334: HIVE-27353: Show saved snapshot of materialized view source tables
veghlaci05 commented on code in PR #4334:
URL: https://github.com/apache/hive/pull/4334#discussion_r1214318367
##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/desc/formatter/TextDescTableFormatter.java:
##########
@@ -248,27 +251,52 @@ private void getViewInfo(StringBuilder tableInfo, Table table, boolean isOutputP
formatOutput("Original Query:", table.getViewOriginalText(), tableInfo);
formatOutput("Expanded Query:", table.getViewExpandedText(), tableInfo);
if (table.isMaterializedView()) {
- formatOutput("Rewrite Enabled:", table.isRewriteEnabled() ? "Yes" : "No", tableInfo);
- formatOutput("Outdated for Rewriting:", table.isOutdatedForRewriting() == null ? "Unknown"
- : table.isOutdatedForRewriting() ? "Yes" : "No", tableInfo);
- tableInfo.append(LINE_DELIM).append("# Materialized View Source table information").append(LINE_DELIM);
- TextMetaDataTable metaDataTable = new TextMetaDataTable();
- metaDataTable.addRow("Table name", "I/U/D since last rebuild");
- List<SourceTable> sourceTableList = new ArrayList<>(table.getMVMetadata().getSourceTables());
-
- sourceTableList.sort(Comparator.<SourceTable, String>comparing(sourceTable -> sourceTable.getTable().getDbName())
- .thenComparing(sourceTable -> sourceTable.getTable().getTableName()));
- for (SourceTable sourceTable : sourceTableList) {
- String qualifiedTableName = TableName.getQualified(
- sourceTable.getTable().getCatName(),
- sourceTable.getTable().getDbName(),
- sourceTable.getTable().getTableName());
- metaDataTable.addRow(qualifiedTableName,
- String.format("%d/%d/%d",
- sourceTable.getInsertedCount(), sourceTable.getUpdatedCount(), sourceTable.getDeletedCount()));
- }
- tableInfo.append(metaDataTable.renderTable(isOutputPadded));
+ getMaterializedViewInfo(tableInfo, table, isOutputPadded);
+ }
+ }
+
+ private static void getMaterializedViewInfo(StringBuilder tableInfo, Table table, boolean isOutputPadded) {
+ formatOutput("Rewrite Enabled:", table.isRewriteEnabled() ? "Yes" : "No", tableInfo);
+ formatOutput("Outdated for Rewriting:", table.isOutdatedForRewriting() == null ? "Unknown"
+ : table.isOutdatedForRewriting() ? "Yes" : "No", tableInfo);
+ tableInfo.append(LINE_DELIM).append("# Materialized View Source table information").append(LINE_DELIM);
+ TextMetaDataTable metaDataTable = new TextMetaDataTable();
+ metaDataTable.addRow("Table name", "Snapshot");
+ List<SourceTable> sourceTableList = new ArrayList<>(table.getMVMetadata().getSourceTables());
+
+ sourceTableList.sort(Comparator.<SourceTable, String>comparing(sourceTable -> sourceTable.getTable().getDbName())
+ .thenComparing(sourceTable -> sourceTable.getTable().getTableName()));
+
+ MaterializationSnapshotFormatter snapshotFormatter =
+ createMaterializationSnapshotFormatter(table.getMVMetadata().getSnapshot());
+
+ for (SourceTable sourceTable : sourceTableList) {
+ String qualifiedTableName = TableName.getDbTable(
+ sourceTable.getTable().getDbName(),
+ sourceTable.getTable().getTableName());
+ metaDataTable.addRow(qualifiedTableName,
+ snapshotFormatter.getSnapshotOf(qualifiedTableName));
}
+ tableInfo.append(metaDataTable.renderTable(isOutputPadded));
+ }
+
+ private static MaterializationSnapshotFormatter createMaterializationSnapshotFormatter(
+ MaterializationSnapshot snapshot) {
+ if (snapshot != null && snapshot.getTableSnapshots() != null && !snapshot.getTableSnapshots().isEmpty()) {
+ return qualifiedTableName -> snapshot.getTableSnapshots().get(qualifiedTableName).toString();
Review Comment:
I think `snapshot.getTableSnapshots().get(qualifiedTableName)` still can return null if it has no value for the given table, and that would cause an NPE. Or am I missing sth here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org