This is an automated email from the ASF dual-hosted git repository.

zabetak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git

commit 59e8f0d9eac8fce6a0586ef1a3deef53a774c86a
Author: Stamatis Zampetakis <[email protected]>
AuthorDate: Wed Jul 17 15:40:39 2024 +0200

    HIVE-28376: Remove unused Hive object from RelOptHiveTable (Stamatis 
Zampetakis reviewed by Simhadri Govindappa, Kokila N)
    
    The Hive object is not used inside RelOptHiveTable so keeping a reference 
to it is wasting memory and also complicates creation of RelOptHiveTable 
objects (constructor parameter).
    
    Moreover, the Hive objects have thread local scope so in general they 
shouldn't be passed around cause their lifecycle becomes harder to manage.
    
    Close apache/hive#5354
---
 .../hadoop/hive/ql/metadata/HiveMaterializedViewsRegistry.java    | 4 ++--
 .../apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java  | 8 ++------
 ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java   | 6 +++---
 .../hadoop/hive/ql/metadata/TestMaterializedViewsCache.java       | 2 +-
 .../hive/ql/optimizer/calcite/reloperators/TestHiveTableScan.java | 2 +-
 5 files changed, 9 insertions(+), 13 deletions(-)

diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveMaterializedViewsRegistry.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveMaterializedViewsRegistry.java
index 19e3759ec87..93ce92faf89 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveMaterializedViewsRegistry.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveMaterializedViewsRegistry.java
@@ -476,7 +476,7 @@ public final class HiveMaterializedViewsRegistry {
       // for materialized views.
       RelOptHiveTable optTable = new RelOptHiveTable(null, 
cluster.getTypeFactory(), fullyQualifiedTabName,
           rowType, viewTable, nonPartitionColumns, partitionColumns, new 
ArrayList<>(),
-          conf, null, new QueryTables(true), new HashMap<>(), new HashMap<>(), 
new AtomicInteger());
+          conf, new QueryTables(true), new HashMap<>(), new HashMap<>(), new 
AtomicInteger());
       DruidTable druidTable = new DruidTable(new DruidSchema(address, address, 
false),
           dataSource, RelDataTypeImpl.proto(rowType), metrics, 
DruidTable.DEFAULT_TIMESTAMP_COLUMN,
           intervals, null, null);
@@ -491,7 +491,7 @@ public final class HiveMaterializedViewsRegistry {
       // for materialized views.
       RelOptHiveTable optTable = new RelOptHiveTable(null, 
cluster.getTypeFactory(), fullyQualifiedTabName,
           rowType, viewTable, nonPartitionColumns, partitionColumns, new 
ArrayList<>(),
-          conf, null, new QueryTables(true), new HashMap<>(), new HashMap<>(), 
new AtomicInteger());
+          conf, new QueryTables(true), new HashMap<>(), new HashMap<>(), new 
AtomicInteger());
       tableRel = new HiveTableScan(cluster, 
cluster.traitSetOf(HiveRelNode.CONVENTION), optTable,
           viewTable.getTableName(), null, false, false);
     }
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java 
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java
index b1dd697b86f..473c5d5fd5b 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java
@@ -56,7 +56,6 @@ import org.apache.hadoop.hive.metastore.api.Order;
 import org.apache.hadoop.hive.ql.exec.ColumnInfo;
 import org.apache.hadoop.hive.ql.metadata.ForeignKeyInfo;
 import org.apache.hadoop.hive.ql.metadata.ForeignKeyInfo.ForeignKeyCol;
-import org.apache.hadoop.hive.ql.metadata.Hive;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
 import org.apache.hadoop.hive.ql.metadata.PartitionIterable;
 import org.apache.hadoop.hive.ql.metadata.PrimaryKeyInfo;
@@ -107,8 +106,6 @@ public class RelOptHiveTable implements RelOptTable {
   private List<RelReferentialConstraint>          referentialConstraints;
   private boolean                                 
fetchedReferentialConstraints;
   private final HiveConf                          hiveConf;
-
-  private final Hive                              db;
   private final ParsedQueryTables                 tablesCache;
   private final Map<String, PrunedPartitionList>  partitionCache;
   private final Map<String, ColumnStatsList>      colStatsCache;
@@ -122,7 +119,7 @@ public class RelOptHiveTable implements RelOptTable {
 
   public RelOptHiveTable(RelOptSchema calciteSchema, RelDataTypeFactory 
typeFactory, List<String> qualifiedTblName,
       RelDataType rowType, Table hiveTblMetadata, List<ColumnInfo> 
hiveNonPartitionCols, List<ColumnInfo> hivePartitionCols,
-      List<VirtualColumn> hiveVirtualCols, HiveConf hconf, Hive db, 
ParsedQueryTables tabNameToTabObject,
+      List<VirtualColumn> hiveVirtualCols, HiveConf hconf, ParsedQueryTables 
tabNameToTabObject,
       Map<String, PrunedPartitionList> partitionCache, Map<String, 
ColumnStatsList> colStatsCache,
       AtomicInteger noColsMissingStats) {
     this.schema = calciteSchema;
@@ -139,7 +136,6 @@ public class RelOptHiveTable implements RelOptTable {
     this.noOfNonVirtualCols = hiveNonPartitionCols.size() + 
hivePartitionCols.size();
     this.hiveVirtualCols = ImmutableList.copyOf(hiveVirtualCols);
     this.hiveConf = hconf;
-    this.db = db;
     this.tablesCache = tabNameToTabObject;
     this.partitionCache = partitionCache;
     this.colStatsCache = colStatsCache;
@@ -226,7 +222,7 @@ public class RelOptHiveTable implements RelOptTable {
     // 3. Build new Table
     return new RelOptHiveTable(this.schema, this.typeFactory, 
this.qualifiedTblName, newRowType,
         this.hiveTblMetadata, newHiveNonPartitionCols, newHivePartitionCols, 
newHiveVirtualCols,
-        this.hiveConf, this.db, this.tablesCache, this.partitionCache, 
this.colStatsCache,
+        this.hiveConf, this.tablesCache, this.partitionCache, 
this.colStatsCache,
         this.noColsMissingStats);
   }
 
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
index 6a55ee9147e..24680c113f5 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
@@ -3055,7 +3055,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
                 intervals, null, null);
             optTable = new RelOptHiveTable(relOptSchema, 
relOptSchema.getTypeFactory(), fullyQualifiedTabName,
                 rowType, tabMetaData, nonPartitionColumns, partitionColumns, 
virtualCols, conf,
-                db, tabNameToTabObject, partitionCache, colStatsCache, 
noColsMissingStats);
+                tabNameToTabObject, partitionCache, colStatsCache, 
noColsMissingStats);
             final TableScan scan = new HiveTableScan(cluster, 
cluster.traitSetOf(HiveRelNode.CONVENTION),
                 optTable, null == tableAlias ? tabMetaData.getTableName() : 
tableAlias,
                 getAliasId(tableAlias, qb), HiveConf.getBoolVar(conf,
@@ -3066,7 +3066,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
           } else {
             optTable = new RelOptHiveTable(relOptSchema, 
relOptSchema.getTypeFactory(), fullyQualifiedTabName,
                   rowType, tabMetaData, nonPartitionColumns, partitionColumns, 
virtualCols, conf,
-                  db, tabNameToTabObject, partitionCache, colStatsCache, 
noColsMissingStats);
+                  tabNameToTabObject, partitionCache, colStatsCache, 
noColsMissingStats);
             final HiveTableScan hts = new HiveTableScan(cluster,
                   cluster.traitSetOf(HiveRelNode.CONVENTION), optTable,
                   null == tableAlias ? tabMetaData.getTableName() : tableAlias,
@@ -3131,7 +3131,7 @@ public class CalcitePlanner extends SemanticAnalyzer {
           fullyQualifiedTabName.add(tabMetaData.getTableName());
           optTable = new RelOptHiveTable(relOptSchema, 
relOptSchema.getTypeFactory(), fullyQualifiedTabName,
               rowType, tabMetaData, nonPartitionColumns, partitionColumns, 
virtualCols, conf,
-              db, tabNameToTabObject, partitionCache, colStatsCache, 
noColsMissingStats);
+              tabNameToTabObject, partitionCache, colStatsCache, 
noColsMissingStats);
           // Build Hive Table Scan Rel
           tableRel = new HiveTableScan(cluster, 
cluster.traitSetOf(HiveRelNode.CONVENTION), optTable,
               null == tableAlias ? tabMetaData.getTableName() : tableAlias,
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestMaterializedViewsCache.java
 
b/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestMaterializedViewsCache.java
index 941adf697ea..fa0f1c59535 100644
--- 
a/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestMaterializedViewsCache.java
+++ 
b/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestMaterializedViewsCache.java
@@ -335,7 +335,7 @@ class TestMaterializedViewsCache {
     public DummyRel(Table table) {
       this.dummyTable = new RelOptHiveTable(null, null,
               singletonList(table.getDbName() + "." + table.getTableName()), 
null, table,
-              emptyList(), emptyList(), emptyList(), null, null, null,
+              emptyList(), emptyList(), emptyList(), null, null,
               null, null, null);
     }
 
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/TestHiveTableScan.java
 
b/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/TestHiveTableScan.java
index 3e2bc6e1b44..a2991e78598 100644
--- 
a/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/TestHiveTableScan.java
+++ 
b/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/TestHiveTableScan.java
@@ -69,7 +69,7 @@ public class TestHiveTableScan {
     RelDataType tblType = factory.builder().add("col1", 
SqlTypeName.INTEGER).add("col2", SqlTypeName.VARCHAR).build();
     Table tblMeta = new Table("default", "dummy");
     return new RelOptHiveTable(null, factory, Arrays.asList("default", 
"dummy"), tblType, tblMeta,
-        Collections.emptyList(), Collections.emptyList(), 
Collections.emptyList(), new HiveConf(), null,
+        Collections.emptyList(), Collections.emptyList(), 
Collections.emptyList(), new HiveConf(),
         new QueryTables(), new HashMap<>(), new HashMap<>(), new 
AtomicInteger(0));
   }
 }

Reply via email to