You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/11/17 10:15:39 UTC
[GitHub] [hive] vnhive opened a new pull request #1681: Hive 24397
vnhive opened a new pull request #1681:
URL: https://github.com/apache/hive/pull/1681
HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
The GetProjectionsSpec object is added to GetTablesRequest. The projection specification are passed down
to the RawStore implementations to enable creating a subset of the columns that are returned.
This patch does not introduce any customer facing changes.
----------------------------------------------------------------
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.
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
[GitHub] [hive] vnhive commented on pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
vnhive commented on pull request #1681:
URL: https://github.com/apache/hive/pull/1681#issuecomment-736201182
@vihangk1 Addressed all your comments in this push.
----------------------------------------------------------------
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.
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
[GitHub] [hive] github-actions[bot] commented on pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #1681:
URL: https://github.com/apache/hive/pull/1681#issuecomment-772120062
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Feel free to reach out on the dev@hive.apache.org list if the patch is in need of reviews.
----------------------------------------------------------------
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.
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
[GitHub] [hive] nrg4878 commented on a change in pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
nrg4878 commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r533887656
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1912,19 +1972,19 @@ private Table convertToTable(MTable mtbl) throws MetaException {
// for backwards compatibility with old metastore persistence
if (mtbl.getViewOriginalText() != null) {
tableType = TableType.VIRTUAL_VIEW.toString();
- } else if (Boolean.parseBoolean(mtbl.getParameters().get("EXTERNAL"))) {
+ } else if (mtbl.getParameters() != null && Boolean.parseBoolean(mtbl.getParameters().get("EXTERNAL"))) {
tableType = TableType.EXTERNAL_TABLE.toString();
} else {
tableType = TableType.MANAGED_TABLE.toString();
}
}
Map<String, String> parameters = convertMap(mtbl.getParameters());
boolean isAcidTable = TxnUtils.isAcidTable(parameters);
- final Table t = new Table(mtbl.getTableName(), mtbl.getDatabase().getName(), mtbl
- .getOwner(), mtbl.getCreateTime(), mtbl.getLastAccessTime(), mtbl
- .getRetention(), convertToStorageDescriptor(mtbl.getSd(), false, isAcidTable),
- convertToFieldSchemas(mtbl.getPartitionKeys()), parameters,
- mtbl.getViewOriginalText(), mtbl.getViewExpandedText(), tableType);
+ final Table t = new Table(mtbl.getTableName(), mtbl.getDatabase() != null ? mtbl.getDatabase().getName() : null,
+ mtbl.getOwner(), mtbl.getCreateTime(), mtbl.getLastAccessTime(), mtbl.getRetention(),
Review comment:
nit: remove additional spacing
----------------------------------------------------------------
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.
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
[GitHub] [hive] vnhive commented on a change in pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
vnhive commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r530816743
##########
File path: standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestTablesGetExists.java
##########
@@ -402,6 +393,134 @@ public void testGetTableObjectsByName() throws Exception {
}
+ @Test
+ public void testGetTableObjectsWithProjectionOfSingleField() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Collections.singletonList("sd.location");
+ projectSpec.setFieldList(projectedFields);
+
+ List<Table> tables = client.getTableObjectsByRequest(request);
+
+ Assert.assertEquals("Found tables", 2, tables.size());
+
+ for(Table table : tables) {
+ Assert.assertFalse(table.isSetDbName());
+ Assert.assertFalse(table.isSetCatName());
+ Assert.assertFalse(table.isSetTableName());
+ Assert.assertTrue(table.isSetSd());
+ }
+ }
+
+ @Test
+ public void testGetTableObjectsWithNullProjectionSpec() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(null);
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ List<Table> tables = client.getTableObjectsByRequest(request);
+
+ Assert.assertEquals("Found tables", 2, tables.size());
+ }
+
+ @Test
+ public void testGetTableObjectsWithNonExistentColumn() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList("Invalid1");
+ projectSpec.setFieldList(projectedFields);
+
+ Assert.assertThrows(Exception.class, ()->client.getTableObjectsByRequest(request));
+ }
+
+
+ @Test
+ public void testGetTableObjectsWithNonExistentColumns() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList("Invalid1", "Invalid2");
+ projectSpec.setFieldList(projectedFields);
+
+ Assert.assertThrows(Exception.class, ()->client.getTableObjectsByRequest(request));
+ }
+
+ @Test
+ public void testGetTableObjectsWithEmptyProjection() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList();
+ projectSpec.setFieldList(projectedFields);
+
+ List<Table> tables = client.getTableObjectsByRequest(request);
+
+ Assert.assertEquals("Found tables", 0, tables.size());
+ }
+
+ @Test
+ public void testGetTableObjectsWithProjectionOfMultipleField() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList("database", "tableName", "createTime", "lastAccessTime");
Review comment:
Thank you for this comment. This is an excellent catch from you.
> can we add some nested single valued fields here too. Something other than sd.location?
> like for example. sd.serdeInfo.serializationLib?
Done.
> Also, what is the expected behavior if the user adds a multi-valued field like sd.parameters.
Currently JDO does not support multi-valued fields and we end up returning all the columns. This is the same behaviour as partitions.
> Can we have some tests around that too.
Done !
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1855,43 +1869,81 @@ private MTable getMTable(String catName, String db, String table) {
for (String t : tbl_names) {
lowered_tbl_names.add(normalizeIdentifier(t));
}
+
query = pm.newQuery(MTable.class);
query.setFilter("database.name == db && database.catalogName == cat && tbl_names.contains(tableName)");
query.declareParameters("java.lang.String db, java.lang.String cat, java.util.Collection tbl_names");
- Collection mtables = (Collection) query.execute(db, catName, lowered_tbl_names);
- if (mtables == null || mtables.isEmpty()) {
- // Need to differentiate between an unmatched pattern and a non-existent database
- dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && catalogName == cat");
- dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat");
- dbExistsQuery.setUnique(true);
- dbExistsQuery.setResult("name");
- String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
- if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
- throw new UnknownDBException("Could not find database " +
- DatabaseName.getQualified(catName, db));
+
+ if (projectionSpec == null) {
+ mtables = (List<MTable>) query.execute(db, catName, lowered_tbl_names);
+ }
+ else if(projectionSpec.getFieldList() != null && projectionSpec.getFieldList().size() > 1) {
Review comment:
one returns a multiple columns in each row List<Object[]> and the other returns only one column for each row, List<Object>. The parsing logic does vary in the former case no ? Are you suggesting typecasting to List<Object[]> in both the cases and unifying the logic ?
##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
##########
@@ -2360,6 +2360,21 @@ public Table getTable(String catName, String dbName, String tableName, String va
return deepCopyTables(FilterUtils.filterTablesIfEnabled(isClientFilterEnabled, filterHook, tabs));
}
+ @Override
+ public GetTablesResult getTables(GetTablesRequest req) throws TException {
+ if (processorCapabilities != null)
+ req.setProcessorCapabilities(new ArrayList<String>(Arrays.asList(processorCapabilities)));
+ if (processorIdentifier != null)
+ req.setProcessorIdentifier(processorIdentifier);
+ if (req.getCapabilities() == null) {
Review comment:
Thank you for pointing it out. Fixed!
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1855,43 +1869,89 @@ private MTable getMTable(String catName, String db, String table) {
for (String t : tbl_names) {
lowered_tbl_names.add(normalizeIdentifier(t));
}
+
query = pm.newQuery(MTable.class);
query.setFilter("database.name == db && database.catalogName == cat && tbl_names.contains(tableName)");
query.declareParameters("java.lang.String db, java.lang.String cat, java.util.Collection tbl_names");
- Collection mtables = (Collection) query.execute(db, catName, lowered_tbl_names);
- if (mtables == null || mtables.isEmpty()) {
- // Need to differentiate between an unmatched pattern and a non-existent database
- dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && catalogName == cat");
- dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat");
- dbExistsQuery.setUnique(true);
- dbExistsQuery.setResult("name");
- String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
- if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
- throw new UnknownDBException("Could not find database " +
- DatabaseName.getQualified(catName, db));
+
+ List<String> projectionFields = null;
+
+ // If a projection specification has been set, validate it and translate it to JDO columns.
+ if (projectionSpec != null) {
+ //Validate the projection fields for multi-valued fields.
+ projectionFields = TableFields.getMFieldNames(projectionSpec.getFieldList());
+ }
+
+ // If the JDO translation resulted in valid JDO columns names, use it to create a projection for the JDO query.
+ if (projectionFields != null) {
+ // fetch partially filled tables using result clause
+ query.setResult(Joiner.on(',').join(projectionFields));
+ }
+
+ if (projectionFields == null) {
+ mtables = (List<MTable>) query.execute(db, catName, lowered_tbl_names);
+ } else {
+ if (projectionFields.size() > 1) {
+ // Execute the query to fetch the partial results.
+ List<Object[]> results = (List<Object[]>) query.execute(db, catName, lowered_tbl_names);
+ // Declare the tables array to return the list of tables
+ mtables = new ArrayList<>(results.size());
+ // Iterate through each row of the result and create the MTable object.
+ for (Object[] row : results) {
+ MTable mtable = new MTable();
+ int i = 0;
+ for (Object val : row) {
+ MetaStoreServerUtils.setNestedProperty(mtable, projectionFields.get(i), val, true);
+ i++;
+ }
+ mtables.add(mtable);
+ }
+ } else if (projectionFields.size() == 1) {
+ // Execute the query to fetch the partial results.
+ List<Object> results = (List<Object>) query.execute(db, catName, lowered_tbl_names);
+ // Iterate through each row of the result and create the MTable object.
+ mtables = new ArrayList<>(results.size());
+ for (Object row : results) {
+ MTable mtable = new MTable();
+ MetaStoreServerUtils.setNestedProperty(mtable, projectionFields.get(0), row, true);
+ mtables.add(mtable);
+ }
}
+ }
+
+ if (mtables == null || mtables.isEmpty()) {
+ verifyDBExists(catName, db);
Review comment:
Done !
##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
##########
@@ -733,6 +733,27 @@ Table getTable(String catName, String dbName, String tableName,
List<Table> getTableObjectsByName(String dbName, List<String> tableNames)
throws MetaException, InvalidOperationException, UnknownDBException, TException;
+
+ /**
+ * Get tables as objects (rather than just fetching their names). This is more expensive and
+ * should only be used if you actually need all the information about the tables.
+ * @param request GetTablesRequest Object.
+ * @return A list of objects representing the tables.
+ * Only the tables that can be retrieved from the database are returned. For example,
+ * if none of the requested tables could be retrieved, an empty list is returned.
+ * There is no guarantee of ordering of the returned tables.
+ * @throws InvalidOperationException
+ * The input to this operation is invalid (e.g., the list of tables names is null)
+ * @throws UnknownDBException
+ * The requested database could not be fetched.
+ * @throws TException
+ * A thrift communication error occurred
+ * @throws MetaException
+ * Any other errors
+ */
+ List<Table> getTableObjectsByRequest(GetTablesRequest request)
Review comment:
> Does the method name have to include byRequest? Its self-evident by the signature right? How about
> getTables(GetTablesRequest request).
I have added getTables.
> Also, can we keep the return type as GetTablesResponse here so that the interface is more extendable
> in the future?
There is no GetTablesReponse object. There is a TablesResult object. I have changed the method to return this.
##########
File path: standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
##########
@@ -1454,7 +1454,8 @@ struct GetTablesRequest {
3: optional ClientCapabilities capabilities,
4: optional string catName,
5: optional list<string> processorCapabilities,
- 6: optional string processorIdentifier
+ 6: optional string processorIdentifier,
+ 7: optional GetProjectionsSpec projectionSpec
Review comment:
Done !
1. I added a comment inside the definition of GetProjectionSpec, saying that the include and exclude patterns are not supported
2. I throw an Unsupported operation exception from the table API.
3. I have written a test case to verify this.
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1839,13 +1839,27 @@ private MTable getMTable(String catName, String db, String table) {
return nmtbl.mtbl;
}
- @Override
- public List<Table> getTableObjectsByName(String catName, String db, List<String> tbl_names)
- throws MetaException, UnknownDBException {
+ private void verifyDBExists(String catName, String db) throws UnknownDBException {
+ // Need to differentiate between an unmatched pattern and a non-existent database
+ Query dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && catalogName == cat");
+ dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat");
+ dbExistsQuery.setUnique(true);
+ dbExistsQuery.setResult("name");
+ String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
+ if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
+ throw new UnknownDBException("Could not find database " +
+ DatabaseName.getQualified(catName, db));
+ }
+ dbExistsQuery.closeAll();
+ }
+
+ private List<Table> getTableObjectsByNameUtil(String catName, String db, List<String> tbl_names,
Review comment:
I agree, this reduces code. Done !
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1855,43 +1869,81 @@ private MTable getMTable(String catName, String db, String table) {
for (String t : tbl_names) {
lowered_tbl_names.add(normalizeIdentifier(t));
}
+
query = pm.newQuery(MTable.class);
query.setFilter("database.name == db && database.catalogName == cat && tbl_names.contains(tableName)");
query.declareParameters("java.lang.String db, java.lang.String cat, java.util.Collection tbl_names");
- Collection mtables = (Collection) query.execute(db, catName, lowered_tbl_names);
- if (mtables == null || mtables.isEmpty()) {
- // Need to differentiate between an unmatched pattern and a non-existent database
- dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && catalogName == cat");
- dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat");
- dbExistsQuery.setUnique(true);
- dbExistsQuery.setResult("name");
- String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
- if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
- throw new UnknownDBException("Could not find database " +
- DatabaseName.getQualified(catName, db));
+
+ if (projectionSpec == null) {
+ mtables = (List<MTable>) query.execute(db, catName, lowered_tbl_names);
+ }
+ else if(projectionSpec.getFieldList() != null && projectionSpec.getFieldList().size() > 1) {
+ // fetch partially filled tables using result clause
+ query.setResult(Joiner.on(',').join(projectionSpec.getFieldList()));
Review comment:
Done !
##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
##########
@@ -733,6 +733,27 @@ Table getTable(String catName, String dbName, String tableName,
List<Table> getTableObjectsByName(String dbName, List<String> tableNames)
throws MetaException, InvalidOperationException, UnknownDBException, TException;
+
+ /**
+ * Get tables as objects (rather than just fetching their names). This is more expensive and
+ * should only be used if you actually need all the information about the tables.
+ * @param request GetTablesRequest Object.
+ * @return A list of objects representing the tables.
+ * Only the tables that can be retrieved from the database are returned. For example,
+ * if none of the requested tables could be retrieved, an empty list is returned.
+ * There is no guarantee of ordering of the returned tables.
+ * @throws InvalidOperationException
+ * The input to this operation is invalid (e.g., the list of tables names is null)
+ * @throws UnknownDBException
+ * The requested database could not be fetched.
+ * @throws TException
+ * A thrift communication error occurred
+ * @throws MetaException
+ * Any other errors
+ */
+ GetTablesResult getTables(GetTablesRequest request)
Review comment:
I agree to this.
Request/Response objects are thrift serialization objects and are not meant for use outside the HiveMetaStore (client and server).
I also agree to your argument that if more fields are added to them tomorrow, these will need to be accounted for across all its usages.
I have changed this and updated the pull request.
##########
File path: standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestTablesGetExists.java
##########
@@ -505,10 +524,69 @@ public void testGetTableObjectsWithProjectionOfMultipleField() throws Exception
request.setDbName(DEFAULT_DATABASE);
GetProjectionsSpec projectSpec = request.getProjectionSpec();
- List<String> projectedFields = Arrays.asList("database", "tableName", "createTime", "lastAccessTime");
+ List<String> projectedFields = Arrays.asList("dbName", "tableName", "createTime", "lastAccessTime");
+ projectSpec.setFieldList(projectedFields);
+
+ GetTablesResult result = client.getTables(request);
+ List<Table> tables = result.getTables();
+
+ Assert.assertEquals("Found tables", 2, tables.size());
+
+ for(Table table : tables) {
+ Assert.assertTrue(table.isSetDbName());
+ Assert.assertTrue(table.isSetTableName());
+ Assert.assertTrue(table.isSetCreateTime());
+ Assert.assertFalse(table.isSetSd());
+ }
+ }
+
+ @Test
+ public void testGetTableObjectsWithProjectionOfSerDeInfoSingleValuedFields() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList("sd.serdeInfo.name", "sd.serdeInfo.serializationLib", "sd.serdeInfo.description");
+ projectSpec.setFieldList(projectedFields);
+
+ GetTablesResult result = client.getTables(request);
+ List<Table> tables = result.getTables();
+
+ Assert.assertEquals("Found tables", 2, tables.size());
+
+ for(Table table : tables) {
+ Assert.assertFalse(table.isSetDbName());
+ Assert.assertTrue(table.isSetSd());
+ StorageDescriptor sd = table.getSd();
+ Assert.assertFalse(sd.isSetCols());
+ Assert.assertTrue(sd.isSetSerdeInfo());
+ SerDeInfo serDeInfo = sd.getSerdeInfo();
Review comment:
Done !
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1912,19 +1972,19 @@ private Table convertToTable(MTable mtbl) throws MetaException {
// for backwards compatibility with old metastore persistence
if (mtbl.getViewOriginalText() != null) {
tableType = TableType.VIRTUAL_VIEW.toString();
- } else if (Boolean.parseBoolean(mtbl.getParameters().get("EXTERNAL"))) {
+ } else if (mtbl.getParameters() != null && Boolean.parseBoolean(mtbl.getParameters().get("EXTERNAL"))) {
tableType = TableType.EXTERNAL_TABLE.toString();
} else {
tableType = TableType.MANAGED_TABLE.toString();
}
}
Map<String, String> parameters = convertMap(mtbl.getParameters());
boolean isAcidTable = TxnUtils.isAcidTable(parameters);
- final Table t = new Table(mtbl.getTableName(), mtbl.getDatabase().getName(), mtbl
- .getOwner(), mtbl.getCreateTime(), mtbl.getLastAccessTime(), mtbl
- .getRetention(), convertToStorageDescriptor(mtbl.getSd(), false, isAcidTable),
- convertToFieldSchemas(mtbl.getPartitionKeys()), parameters,
- mtbl.getViewOriginalText(), mtbl.getViewExpandedText(), tableType);
+ final Table t = new Table(mtbl.getTableName(), mtbl.getDatabase() != null ? mtbl.getDatabase().getName() : null,
+ mtbl.getOwner(), mtbl.getCreateTime(), mtbl.getLastAccessTime(), mtbl.getRetention(),
Review comment:
Done !
----------------------------------------------------------------
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.
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
[GitHub] [hive] vnhive commented on pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
vnhive commented on pull request #1681:
URL: https://github.com/apache/hive/pull/1681#issuecomment-735521533
In the latest pull request I have addressed the comment to change the API to getTables and also return a GetTablesResult object instead of List<Table>
----------------------------------------------------------------
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.
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
[GitHub] [hive] nrg4878 commented on a change in pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
nrg4878 commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r533887465
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1839,13 +1839,27 @@ private MTable getMTable(String catName, String db, String table) {
return nmtbl.mtbl;
}
- @Override
- public List<Table> getTableObjectsByName(String catName, String db, List<String> tbl_names)
- throws MetaException, UnknownDBException {
+ private void verifyDBExists(String catName, String db) throws UnknownDBException {
+ // Need to differentiate between an unmatched pattern and a non-existent database
+ Query dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && catalogName == cat");
+ dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat");
+ dbExistsQuery.setUnique(true);
+ dbExistsQuery.setResult("name");
+ String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
+ if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
+ throw new UnknownDBException("Could not find database " +
+ DatabaseName.getQualified(catName, db));
+ }
+ dbExistsQuery.closeAll();
+ }
+
+ private List<Table> getTableObjectsByNameUtil(String catName, String db, List<String> tbl_names,
Review comment:
instead of adding getTableObjectsByNameUtil() method thats called by both flavors of getTableObjectsByName(), should we use
1) getTableObjectsByName(String catName, String db, List<String> tbl_names,
GetProjectionsSpec projectionsSpec)
and then
2) getTableObjectsByName(String catName, String db, List<String> tbl_names)
should invoke #1 with a null projectionSpec value
----------------------------------------------------------------
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.
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
[GitHub] [hive] vihangk1 commented on a change in pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
vihangk1 commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r528908297
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1855,43 +1869,81 @@ private MTable getMTable(String catName, String db, String table) {
for (String t : tbl_names) {
lowered_tbl_names.add(normalizeIdentifier(t));
}
+
query = pm.newQuery(MTable.class);
query.setFilter("database.name == db && database.catalogName == cat && tbl_names.contains(tableName)");
query.declareParameters("java.lang.String db, java.lang.String cat, java.util.Collection tbl_names");
- Collection mtables = (Collection) query.execute(db, catName, lowered_tbl_names);
- if (mtables == null || mtables.isEmpty()) {
- // Need to differentiate between an unmatched pattern and a non-existent database
- dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && catalogName == cat");
- dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat");
- dbExistsQuery.setUnique(true);
- dbExistsQuery.setResult("name");
- String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
- if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
- throw new UnknownDBException("Could not find database " +
- DatabaseName.getQualified(catName, db));
+
+ if (projectionSpec == null) {
+ mtables = (List<MTable>) query.execute(db, catName, lowered_tbl_names);
+ }
+ else if(projectionSpec.getFieldList() != null && projectionSpec.getFieldList().size() > 1) {
Review comment:
why do we need to code blockes for projectionSpec fieldList size > 1 and == 1? the code looks very similar.
##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
##########
@@ -733,6 +733,27 @@ Table getTable(String catName, String dbName, String tableName,
List<Table> getTableObjectsByName(String dbName, List<String> tableNames)
throws MetaException, InvalidOperationException, UnknownDBException, TException;
+
+ /**
+ * Get tables as objects (rather than just fetching their names). This is more expensive and
+ * should only be used if you actually need all the information about the tables.
+ * @param request GetTablesRequest Object.
+ * @return A list of objects representing the tables.
+ * Only the tables that can be retrieved from the database are returned. For example,
+ * if none of the requested tables could be retrieved, an empty list is returned.
+ * There is no guarantee of ordering of the returned tables.
+ * @throws InvalidOperationException
+ * The input to this operation is invalid (e.g., the list of tables names is null)
+ * @throws UnknownDBException
+ * The requested database could not be fetched.
+ * @throws TException
+ * A thrift communication error occurred
+ * @throws MetaException
+ * Any other errors
+ */
+ List<Table> getTableObjectsByRequest(GetTablesRequest request)
Review comment:
Does the method name have to include byRequest? Its self-evident by the signature right? How about getTables(GetTablesRequest request). Also, can we keep the return type as GetTablesResponse here so that the interface is more extendable in the future?
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1855,43 +1869,81 @@ private MTable getMTable(String catName, String db, String table) {
for (String t : tbl_names) {
lowered_tbl_names.add(normalizeIdentifier(t));
}
+
query = pm.newQuery(MTable.class);
query.setFilter("database.name == db && database.catalogName == cat && tbl_names.contains(tableName)");
query.declareParameters("java.lang.String db, java.lang.String cat, java.util.Collection tbl_names");
- Collection mtables = (Collection) query.execute(db, catName, lowered_tbl_names);
- if (mtables == null || mtables.isEmpty()) {
- // Need to differentiate between an unmatched pattern and a non-existent database
- dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && catalogName == cat");
- dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat");
- dbExistsQuery.setUnique(true);
- dbExistsQuery.setResult("name");
- String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
- if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
- throw new UnknownDBException("Could not find database " +
- DatabaseName.getQualified(catName, db));
+
+ if (projectionSpec == null) {
+ mtables = (List<MTable>) query.execute(db, catName, lowered_tbl_names);
+ }
+ else if(projectionSpec.getFieldList() != null && projectionSpec.getFieldList().size() > 1) {
+ // fetch partially filled tables using result clause
+ query.setResult(Joiner.on(',').join(projectionSpec.getFieldList()));
Review comment:
Can we add a validation method before actually executing the query? That way you don't hit the database query if the projectionSpec has invalid fields and throw an error early. The performance is better and code becomes cleaner since you avoid the logic at 1924-1915 if you validate the fields first.
##########
File path: standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestTablesGetExists.java
##########
@@ -402,6 +393,134 @@ public void testGetTableObjectsByName() throws Exception {
}
+ @Test
+ public void testGetTableObjectsWithProjectionOfSingleField() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Collections.singletonList("sd.location");
+ projectSpec.setFieldList(projectedFields);
+
+ List<Table> tables = client.getTableObjectsByRequest(request);
+
+ Assert.assertEquals("Found tables", 2, tables.size());
+
+ for(Table table : tables) {
+ Assert.assertFalse(table.isSetDbName());
+ Assert.assertFalse(table.isSetCatName());
+ Assert.assertFalse(table.isSetTableName());
+ Assert.assertTrue(table.isSetSd());
+ }
+ }
+
+ @Test
+ public void testGetTableObjectsWithNullProjectionSpec() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(null);
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ List<Table> tables = client.getTableObjectsByRequest(request);
+
+ Assert.assertEquals("Found tables", 2, tables.size());
+ }
+
+ @Test
+ public void testGetTableObjectsWithNonExistentColumn() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList("Invalid1");
+ projectSpec.setFieldList(projectedFields);
+
+ Assert.assertThrows(Exception.class, ()->client.getTableObjectsByRequest(request));
+ }
+
+
+ @Test
+ public void testGetTableObjectsWithNonExistentColumns() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList("Invalid1", "Invalid2");
+ projectSpec.setFieldList(projectedFields);
+
+ Assert.assertThrows(Exception.class, ()->client.getTableObjectsByRequest(request));
+ }
+
+ @Test
+ public void testGetTableObjectsWithEmptyProjection() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList();
+ projectSpec.setFieldList(projectedFields);
+
+ List<Table> tables = client.getTableObjectsByRequest(request);
+
+ Assert.assertEquals("Found tables", 0, tables.size());
+ }
+
+ @Test
+ public void testGetTableObjectsWithProjectionOfMultipleField() throws Exception {
+ List<String> tableNames = new ArrayList<>();
+ tableNames.add(testTables[0].getTableName());
+ tableNames.add(testTables[1].getTableName());
+
+ GetTablesRequest request = new GetTablesRequest();
+ request.setProjectionSpec(new GetProjectionsSpec());
+ request.setTblNames(tableNames);
+ request.setDbName(DEFAULT_DATABASE);
+
+ GetProjectionsSpec projectSpec = request.getProjectionSpec();
+ List<String> projectedFields = Arrays.asList("database", "tableName", "createTime", "lastAccessTime");
Review comment:
can we add some nested single valued fields here too. Something other than sd.location? like for example. sd.serdeInfo.serializationLib? Also, what is the expected behavior if the user adds a multi-valued field like sd.parameters. Can we have some tests around that too.
##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
##########
@@ -2360,6 +2360,20 @@ public Table getTable(String catName, String dbName, String tableName, String va
return deepCopyTables(FilterUtils.filterTablesIfEnabled(isClientFilterEnabled, filterHook, tabs));
}
+ @Override
+ public List<Table> getTableObjectsByRequest(GetTablesRequest req) throws TException {
Review comment:
Do you need to do any special handling of SessionMetastoreClient?
##########
File path: standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
##########
@@ -1454,7 +1454,8 @@ struct GetTablesRequest {
3: optional ClientCapabilities capabilities,
4: optional string catName,
5: optional list<string> processorCapabilities,
- 6: optional string processorIdentifier
+ 6: optional string processorIdentifier,
+ 7: optional GetProjectionsSpec projectionSpec
Review comment:
can you add a comment here saying what is support and what is not? For example, ProjectionSpec has fields to filter the parameters too. But we don't support it here. The code should also validate such cases and throw a MetaException with appropriate error message.
----------------------------------------------------------------
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.
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
[GitHub] [hive] github-actions[bot] closed pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #1681:
URL: https://github.com/apache/hive/pull/1681
----------------------------------------------------------------
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.
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
[GitHub] [hive] nrg4878 commented on a change in pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
nrg4878 commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r533881997
##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
##########
@@ -733,6 +733,27 @@ Table getTable(String catName, String dbName, String tableName,
List<Table> getTableObjectsByName(String dbName, List<String> tableNames)
throws MetaException, InvalidOperationException, UnknownDBException, TException;
+
+ /**
+ * Get tables as objects (rather than just fetching their names). This is more expensive and
+ * should only be used if you actually need all the information about the tables.
+ * @param request GetTablesRequest Object.
+ * @return A list of objects representing the tables.
+ * Only the tables that can be retrieved from the database are returned. For example,
+ * if none of the requested tables could be retrieved, an empty list is returned.
+ * There is no guarantee of ordering of the returned tables.
+ * @throws InvalidOperationException
+ * The input to this operation is invalid (e.g., the list of tables names is null)
+ * @throws UnknownDBException
+ * The requested database could not be fetched.
+ * @throws TException
+ * A thrift communication error occurred
+ * @throws MetaException
+ * Any other errors
+ */
+ GetTablesResult getTables(GetTablesRequest request)
Review comment:
This method should have a different signature. So the Request/Result objects are serialized/deserialized between the client and the server. The client side application code (for example HiveServer2) should not have to deal with Request/Response objects.
So HS2 will invoke something like this
IMetastoreClient.getTableObjectsByName(String catName, String dbName, List<String> tableNames)
or
IMetastoreClient.getTableObjectsByName(String catName, String dbName, List<String> tableNames, GetProjectionSpec projectionSpec)
These 2 methods internally have to build a GetTablesRequest object based on the arguments, make the thrift call which returns the GetTablesResults object, which then have to be returned to calls as List<Table>
So the signature should be something like this
List<Table> getTables/getTableObjectsByName(catName, dbName, tableNames, projectionSpec)
----------------------------------------------------------------
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.
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
[GitHub] [hive] nrg4878 commented on pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
nrg4878 commented on pull request #1681:
URL: https://github.com/apache/hive/pull/1681#issuecomment-738974480
Fix has been merged to master. Thank you @vnhive
----------------------------------------------------------------
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.
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
[GitHub] [hive] vnhive commented on a change in pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
vnhive commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r530803306
##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
##########
@@ -2360,6 +2360,20 @@ public Table getTable(String catName, String dbName, String tableName, String va
return deepCopyTables(FilterUtils.filterTablesIfEnabled(isClientFilterEnabled, filterHook, tabs));
}
+ @Override
+ public List<Table> getTableObjectsByRequest(GetTablesRequest req) throws TException {
Review comment:
You are referring to SessionHiveMetaStoreClient right ?
SessionHiveMetaStoreClient does not have an implementation for get_partitions_with_specs and piggybacks on the implementation in its superclass (HiveMetaStoreClient) from the inheritance hierarchy. I just followed the same pattern here.
Also it just returns a list of table objects, basically a read query and should work the same across sessions, since, it just returns persisted session information.
----------------------------------------------------------------
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.
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
[GitHub] [hive] nrg4878 commented on a change in pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
nrg4878 commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r533882298
##########
File path: standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
##########
@@ -2360,6 +2360,21 @@ public Table getTable(String catName, String dbName, String tableName, String va
return deepCopyTables(FilterUtils.filterTablesIfEnabled(isClientFilterEnabled, filterHook, tabs));
}
+ @Override
+ public GetTablesResult getTables(GetTablesRequest req) throws TException {
+ if (processorCapabilities != null)
+ req.setProcessorCapabilities(new ArrayList<String>(Arrays.asList(processorCapabilities)));
+ if (processorIdentifier != null)
+ req.setProcessorIdentifier(processorIdentifier);
+ if (req.getCapabilities() == null) {
Review comment:
duplicate setCapabilities() call.
----------------------------------------------------------------
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.
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
[GitHub] [hive] github-actions[bot] commented on pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #1681:
URL: https://github.com/apache/hive/pull/1681#issuecomment-772120062
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Feel free to reach out on the dev@hive.apache.org list if the patch is in need of reviews.
----------------------------------------------------------------
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.
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
[GitHub] [hive] vnhive commented on pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
vnhive commented on pull request #1681:
URL: https://github.com/apache/hive/pull/1681#issuecomment-736976841
@nrg4878 The change to the signature of this method was proposed by @vihangk1 and I agreed with him because the corresponding partition method returns a GetPartitionResponse. Please see the corresponding method below.
GetPartitionResponse getPartitionRequest(GetPartitionRequest req) throws NoSuchObjectException, MetaException, TException;
----------------------------------------------------------------
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.
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
[GitHub] [hive] nrg4878 commented on a change in pull request #1681: HIVE-24397 : Add the projection specification to the table request object and add placeholders in ObjectStore.java
Posted by GitBox <gi...@apache.org>.
nrg4878 commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r533886236
##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1855,43 +1869,89 @@ private MTable getMTable(String catName, String db, String table) {
for (String t : tbl_names) {
lowered_tbl_names.add(normalizeIdentifier(t));
}
+
query = pm.newQuery(MTable.class);
query.setFilter("database.name == db && database.catalogName == cat && tbl_names.contains(tableName)");
query.declareParameters("java.lang.String db, java.lang.String cat, java.util.Collection tbl_names");
- Collection mtables = (Collection) query.execute(db, catName, lowered_tbl_names);
- if (mtables == null || mtables.isEmpty()) {
- // Need to differentiate between an unmatched pattern and a non-existent database
- dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && catalogName == cat");
- dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat");
- dbExistsQuery.setUnique(true);
- dbExistsQuery.setResult("name");
- String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
- if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
- throw new UnknownDBException("Could not find database " +
- DatabaseName.getQualified(catName, db));
+
+ List<String> projectionFields = null;
+
+ // If a projection specification has been set, validate it and translate it to JDO columns.
+ if (projectionSpec != null) {
+ //Validate the projection fields for multi-valued fields.
+ projectionFields = TableFields.getMFieldNames(projectionSpec.getFieldList());
+ }
+
+ // If the JDO translation resulted in valid JDO columns names, use it to create a projection for the JDO query.
+ if (projectionFields != null) {
+ // fetch partially filled tables using result clause
+ query.setResult(Joiner.on(',').join(projectionFields));
+ }
+
+ if (projectionFields == null) {
+ mtables = (List<MTable>) query.execute(db, catName, lowered_tbl_names);
+ } else {
+ if (projectionFields.size() > 1) {
+ // Execute the query to fetch the partial results.
+ List<Object[]> results = (List<Object[]>) query.execute(db, catName, lowered_tbl_names);
+ // Declare the tables array to return the list of tables
+ mtables = new ArrayList<>(results.size());
+ // Iterate through each row of the result and create the MTable object.
+ for (Object[] row : results) {
+ MTable mtable = new MTable();
+ int i = 0;
+ for (Object val : row) {
+ MetaStoreServerUtils.setNestedProperty(mtable, projectionFields.get(i), val, true);
+ i++;
+ }
+ mtables.add(mtable);
+ }
+ } else if (projectionFields.size() == 1) {
+ // Execute the query to fetch the partial results.
+ List<Object> results = (List<Object>) query.execute(db, catName, lowered_tbl_names);
+ // Iterate through each row of the result and create the MTable object.
+ mtables = new ArrayList<>(results.size());
+ for (Object row : results) {
+ MTable mtable = new MTable();
+ MetaStoreServerUtils.setNestedProperty(mtable, projectionFields.get(0), row, true);
+ mtables.add(mtable);
+ }
}
+ }
+
+ if (mtables == null || mtables.isEmpty()) {
+ verifyDBExists(catName, db);
Review comment:
feels like we should just call getDatabaseInternal() and remove this refactored code verifyDBExists() code altogether. verifyDBExists() only fetches a single column (dbName) in a resultset of 1 row if the DB exists where as getDatabaseInternal() fetches few additional columns in a resultset of 1 row. I dont think it would be a huge performance degradation but the code will be bit cleaner. What do you think?
----------------------------------------------------------------
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.
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