InvisibleProgrammer commented on code in PR #6577:
URL: https://github.com/apache/hive/pull/6577#discussion_r3543771530
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/directsql/MetaStoreDirectSql.java:
##########
@@ -534,6 +537,151 @@ public void addPartitions(List<MPartition> parts,
List<List<MPartitionPrivilege>
directSqlInsertPart.addPartitions(parts, partPrivilegesList,
partColPrivilegesList);
}
+ /**
+ * Gets a suitable column descriptor for an existing table, based on the
latest partitions
+ *
+ * @param cols column list of a partition
+ * @param tblId table id
+ * @return an existing column descriptor which columns matches with @cols.
Null if there is no match.
+ * @throws MetaException
+ */
+ public MColumnDescriptor getColumnDescriptor(List<FieldSchema> cols, long
tblId)
+ throws MetaException {
+
+ if (cols == null || cols.isEmpty()) {
+ return null;
+ }
+
+ // Please note! In case you modify any of those methods, run
TestHMSColumnDescriptorReuse with all the supported databases
+ List<Long> cdCandidates = findTheLatestColumnDescriptors(tblId);
+
+ cdCandidates = filterCandidatesByColumnCount(cdCandidates, cols.size());
+
+ Long matchedColumnDescriptorId =
matchColumnDescriptorWithActualColumns(cdCandidates, cols);
+
+ if (matchedColumnDescriptorId != null) {
+ return pm.getObjectById(MColumnDescriptor.class,
matchedColumnDescriptorId);
+ }
+
+ return null;
+ }
+
+ private @Nullable List<Long> findTheLatestColumnDescriptors(long tblId)
throws MetaException {
+ Query<?> query = null;
+ try {
+ String findLatestDescriptorsSql = """
+ SELECT s."CD_ID"
+ FROM "PARTITIONS" p
+ JOIN "SDS" s ON s."SD_ID" = p."SD_ID"
+ WHERE p."TBL_ID" = ?
+ GROUP BY s."CD_ID"
+ ORDER BY MAX(p."PART_ID") DESC
Review Comment:
I cannot add a limit clause that is compatible with all the supported
databases. However, I can add a limit to the executeWithArray call so that it
will only read the first 20 records.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]