MCPcopy Create free account
hub / github.com/apache/impala / OptimizeStmt

Class OptimizeStmt

fe/src/main/java/org/apache/impala/analysis/OptimizeStmt.java:70–355  ·  view source on GitHub ↗

Representation of an OPTIMIZE TABLE statement used to execute table maintenance tasks in Iceberg tables. It operates in 2+1 modes: full table compaction, partial compaction and no-operation. The mode is decided during analysis. 1. Full table compaction: It rewrites the entire table - compacting smal

Source from the content-addressed store, hash-verified

68 * - there were no files that qualified for the selection criteria in partial mode.
69 */
70public class OptimizeStmt extends DmlStatementBase {
71 // Target table name as seen by the parser.
72 private final TableName originalTableName_;
73 // Data files larger than the given value will only be compacted if they are referenced
74 // from delete files.
75 // The value comes from FILE_SIZE_THRESHOLD_MB, but is converted to bytes.
76 private final long fileSizeThreshold_;
77
78 /////////////////////////////////////////
79 // BEGIN: Members that need to be reset()
80
81 // Target table that should be compacted. May be qualified by analyze().
82 private TableName tableName_;
83 private TableRef tableRef_;
84 // SELECT statement that reads the data that we want to compact.
85 private SelectStmt sourceStmt_;
86 // Output expressions that produce the final results to write to the table.
87 // Set in prepareExpressions().
88 // It will contain one Expr for each column of the table.
89 // The i'th expr produces the i'th column of the table.
90 private List<Expr> resultExprs_ = new ArrayList<>();
91 // For every column of the target table that is referenced in the optional
92 // 'sort.columns' table property, this list will contain the corresponding
93 // result expr from 'resultExprs_'. Before insertion, all rows
94 // will be sorted by these exprs. If the list is empty, no additional sorting by
95 // non-partitioning columns will be performed. The column list must not contain
96 // partition columns.
97 private List<Expr> sortExprs_ = new ArrayList<>();
98 private List<Integer> sortColumns_;
99 private TSortingOrder sortingOrder_ = TSortingOrder.LEXICAL;;
100 // Exprs corresponding to the partition fields of the table.
101 protected List<Expr> partitionKeyExprs_ = new ArrayList<>();
102 // File paths of data files without deletes selected for compaction after file size
103 // filtering.
104 private Set<String> selectedIcebergFilePaths_ = new HashSet<>();
105 // Describes the mode of this OPTIMIZE operation. Decided during analysis.
106 // NOOP: The table was empty or no files were selected for compaction. This means that
107 // the operation has no effect.
108 // PARTIAL: In this mode only the selected files are compacted, all others will remain
109 // unchanged. Files that will be selected:
110 // - data files without deletes that are smaller than fileSizeThreshold_,
111 // - all delete files,
112 // - all data files with deletes.
113 // Possible only if FILE_SIZE_THRESHOLD_MB is set.
114 // REWRITE_ALL: Rewrite all files of the table. This will ensure that the optimized
115 // table has the latest schema and partition spec. Possible if FILE_SIZE_THRESHOLD_MB is
116 // not set in the SQL command or large enough that all files get selected.
117 private TIcebergOptimizationMode mode_;
118
119 // END: Members that need to be reset()
120 /////////////////////////////////////////
121
122 public OptimizeStmt(TableName tableName) {
123 tableName_ = tableName;
124 originalTableName_ = tableName_;
125 fileSizeThreshold_ = -1;
126 }
127

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected