Skip to content

Commit 04eb66a

Browse files
authored
HIVE-29669: EXPLAIN DDL fails on ACID tables with "Cannot find valid write ID list" when HIVE_AUTHORIZATION_ENABLED is enabled (#6546)
1 parent a29be01 commit 04eb66a

11 files changed

Lines changed: 106 additions & 24 deletions

ql/src/java/org/apache/hadoop/hive/ql/exec/DDLPlanUtils.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.collect.Sets;
2727
import java.util.Comparator;
2828
import org.apache.commons.lang3.StringUtils;
29+
import org.apache.hadoop.hive.conf.HiveConf;
2930
import org.apache.hadoop.hive.common.StatsSetupConst;
3031
import org.apache.hadoop.hive.metastore.TableType;
3132
import org.apache.hadoop.hive.metastore.Warehouse;
@@ -239,7 +240,7 @@ public class DDLPlanUtils {
239240
+ TABLE_NAME + "> PARTITION <" + PARTITION_NAME + "> FOR COLUMN <"
240241
+ COLUMN_NAME + "> BUT IT IS NOT SUPPORTED YET. THE BASE64 VALUE FOR THE HISTOGRAM IS <"
241242
+ BASE_64_VALUE + "> ";
242-
243+
243244
/**
244245
* Returns the create database query for a give database name.
245246
*
@@ -516,13 +517,14 @@ public String getAlterTableStmtCol(ColumnStatisticsData columnStatisticsData, St
516517
* Parses the ColumnStatistics for all the columns in a given table and adds the alter table update
517518
* statistics command for each column.
518519
*
520+
* @param conf
519521
* @param tbl
520522
*/
521-
public List<String> getAlterTableStmtTableStatsColsAll(Table tbl)
523+
public List<String> getAlterTableStmtTableStatsColsAll(HiveConf conf, Table tbl)
522524
throws HiveException {
523525
List<String> alterTblStmt = new ArrayList<>();
524526
List<String> accessedColumns = getTableColumnNames(tbl);
525-
List<ColumnStatisticsObj> tableColumnStatistics = Hive.get().getTableColumnStatistics(
527+
List<ColumnStatisticsObj> tableColumnStatistics = Hive.get(conf).getTableColumnStatistics(
526528
tbl, accessedColumns, true);
527529

528530
ColumnStatisticsObj[] columnStatisticsObj = tableColumnStatistics.toArray(new ColumnStatisticsObj[0]);
@@ -648,24 +650,24 @@ public String getAlterTableStmtPartitionStatsBasic(Partition pt) {
648650
return command.render();
649651
}
650652

651-
public List<String> getDDLPlanForPartitionWithStats(Table table,
653+
public List<String> getDDLPlanForPartitionWithStats(HiveConf conf, Table table,
652654
Map<String, List<Partition>> tableToPartitionList
653655
) throws HiveException {
654-
List<String> alterTableStmt = new ArrayList<String>();
656+
List<String> alterTableStmt = new ArrayList<>();
655657
String tableName = table.getTableName();
656658
for (Partition pt : tableToPartitionList.get(tableName)) {
657659
alterTableStmt.add(getAlterTableAddPartition(pt));
658660
alterTableStmt.add(getAlterTableStmtPartitionStatsBasic(pt));
659661
}
660662
String databaseName = table.getDbName();
661-
List<String> partNames = new ArrayList<String>();
663+
List<String> partNames = new ArrayList<>();
662664
//TODO : Check if only Accessed Column Statistics Can be Retrieved From the HMS.
663665
List<String> columnNames = getTableColumnNames(table);
664666
tableToPartitionList.get(tableName).forEach(p -> partNames.add(p.getName()));
665667
Map<String, List<ColumnStatisticsObj>> partitionColStats =
666-
Hive.get().getPartitionColumnStatistics(databaseName,
667-
tableName, partNames, columnNames,
668-
true);
668+
Hive.get(conf).getPartitionColumnStatistics(databaseName,
669+
tableName, partNames, columnNames,
670+
true);
669671
Map<String, String> partitionToActualName = new HashMap<>();
670672
tableToPartitionList.get(tableName).forEach(p -> partitionToActualName.put(p.getName(), getPartitionActualName(p)));
671673
partitionColStats.keySet().stream().sorted().forEach(partitionName ->

ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,9 @@ public void addStats(Table table,List<String> alterTableStmt ,Map<String, List<P
475475
PerfLogger perfLogger = PerfLogger.getPerfLogger(conf, false);
476476
perfLogger.perfLogBegin(ExplainTask.class.getName(), PerfLogger.HIVE_GET_TABLE_COLUMN_STATS);
477477
if (table.isPartitioned()) {
478-
alterTableStmt.addAll(ddlPlanUtils.getDDLPlanForPartitionWithStats(table, tablePartitionsMap));
478+
alterTableStmt.addAll(ddlPlanUtils.getDDLPlanForPartitionWithStats(conf, table, tablePartitionsMap));
479479
} else {
480-
alterTableStmt.addAll(ddlPlanUtils.getAlterTableStmtTableStatsColsAll(table));
480+
alterTableStmt.addAll(ddlPlanUtils.getAlterTableStmtTableStatsColsAll(conf, table));
481481
}
482482
perfLogger.perfLogEnd(ExplainTask.class.getName(), PerfLogger.HIVE_GET_TABLE_COLUMN_STATS);
483483
}
@@ -489,12 +489,12 @@ public void addExplain(String sql , List<String> explainStmt, DDLPlanUtils ddlPl
489489

490490
public void getDDLPlan(PrintStream out) throws Exception {
491491
DDLPlanUtils ddlPlanUtils = new DDLPlanUtils();
492-
Set<String> createDatabase = new TreeSet<String>();
493-
List<String> tableCreateStmt = new LinkedList<String>();
494-
List<String> tableBasicDef = new LinkedList<String>();
495-
List<String> createViewList = new LinkedList<String>();
496-
List<String> alterTableStmt = new LinkedList<String>();
497-
List<String> explainStmt = new LinkedList<String>();
492+
Set<String> createDatabase = new TreeSet<>();
493+
List<String> tableCreateStmt = new LinkedList<>();
494+
List<String> tableBasicDef = new LinkedList<>();
495+
List<String> createViewList = new LinkedList<>();
496+
List<String> alterTableStmt = new LinkedList<>();
497+
List<String> explainStmt = new LinkedList<>();
498498
Map<String, Table> tableMap = new HashMap<>();
499499
Map<String, List<Partition>> tablePartitionsMap = new HashMap<>();
500500
for (ReadEntity ent : work.getInputs()) {

ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HiveMetastoreClientFactoryImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public HiveMetastoreClientFactoryImpl(HiveConf conf) {
4040
public IMetaStoreClient getHiveMetastoreClient() throws HiveAuthzPluginException {
4141
String errMsg = "Error getting metastore client";
4242
try {
43+
Hive db = Hive.getThreadLocal();
44+
if (db != null) {
45+
return db.getMSC();
46+
}
4347
return Hive.get(hiveConf, false).getMSC();
4448
} catch (MetaException e) {
4549
throw new HiveAuthzPluginException(errMsg, e);

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected String getTestDataDir() {
118118
}
119119

120120
@Override
121-
void initHiveConf() {
121+
protected void initHiveConf() {
122122
super.initHiveConf();
123123
//TestTxnCommandsWithSplitUpdateAndVectorization has the vectorized version
124124
//of these tests.

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ String getPartitionColumns() {
155155
public ExpectedException expectedException = ExpectedException.none();
156156

157157
@Override
158-
void initHiveConf() {
158+
protected void initHiveConf() {
159159
super.initHiveConf();
160160
//TestTxnCommands2WithSplitUpdateAndVectorization has the vectorized version
161161
//of these tests.

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2WithAbortCleanupUsingCompactionCycle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public TestTxnCommands2WithAbortCleanupUsingCompactionCycle() {
3030
}
3131

3232
@Override
33-
void initHiveConf() {
33+
protected void initHiveConf() {
3434
super.initHiveConf();
3535
MetastoreConf.setBoolVar(hiveConf, MetastoreConf.ConfVars.COMPACTOR_CLEAN_ABORTS_USING_CLEANER, false);
3636
}

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2WithSplitUpdateAndVectorization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public TestTxnCommands2WithSplitUpdateAndVectorization() {
3434
}
3535

3636
@Override
37-
void initHiveConf() {
37+
protected void initHiveConf() {
3838
super.initHiveConf();
3939
hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED, true);
4040
}

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommandsForMmTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public String toString() {
7474
}
7575

7676
@Override
77-
void initHiveConf() {
77+
protected void initHiveConf() {
7878
super.initHiveConf();
7979
HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_ACID_TRUNCATE_USE_BASE, false);
8080
}

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommandsWithSplitUpdateAndVectorization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public TestTxnCommandsWithSplitUpdateAndVectorization() {
2929
}
3030

3131
@Override
32-
void initHiveConf() {
32+
protected void initHiveConf() {
3333
super.initHiveConf();
3434
hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED, true);
3535
}

ql/src/test/org/apache/hadoop/hive/ql/TxnCommandsBaseForTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void setUp() throws Exception {
116116
HiveMetaStoreClientWithLocalCache.init(hiveConf);
117117
}
118118
}
119-
void initHiveConf() {
119+
protected void initHiveConf() {
120120
hiveConf = new HiveConfForTest(this.getClass());
121121
// Multiple tests requires more than one buckets per write. Use a very small value for grouping size to create
122122
// multiple mapper instances with FileSinkOperators. The number of buckets are depends on the size of the data

0 commit comments

Comments
 (0)