Github user JamesRTaylor commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/12#discussion_r17404995
--- Diff:
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
---
@@ -667,14 +693,104 @@ private PTable getTable(RegionScanner scanner, long
clientTimeStamp, long tableT
} else {
addColumnToTable(results, colName, famName, colKeyValues,
columns, saltBucketNum != null);
}
+ }
+ byte[] tenIdBytes = QueryConstants.EMPTY_BYTE_ARRAY;
+ if (tenantId != null) {
+ tenIdBytes = tenantId.getBytes();
}
-
+ byte[] schNameInBytes = QueryConstants.EMPTY_BYTE_ARRAY;
+ if (schemaName != null) {
+ schNameInBytes = Bytes.toBytes(schemaName.getString());
+ }
+ byte[] tableKey = SchemaUtil.getTableKey(tenIdBytes,
schNameInBytes , PhoenixDatabaseMetaData.SYSTEM_STATS_NAME_BYTES);
+ ImmutableBytesPtr key = new ImmutableBytesPtr(tableKey);
+ Cache<ImmutableBytesPtr, PTable> metaDataCache =
+ GlobalCache.getInstance(this.env).getMetaDataCache();
+ PTable statsPTable = metaDataCache.getIfPresent(key);
+ PTableStats stats = updateStatsInternal(schNameInBytes,
tableNameBytes, columns, statsPTable);
return PTableImpl.makePTable(tenantId, schemaName, tableName,
tableType, indexState, timeStamp,
tableSeqNum, pkName, saltBucketNum, columns, tableType ==
INDEX ? dataTableName : null,
indexes, isImmutableRows, physicalTables, defaultFamilyName,
viewStatement, disableWAL,
- multiTenant, viewType, viewIndexId, indexType);
+ multiTenant, viewType, viewIndexId, indexType, stats);
+ }
+
+ private PTableStats updateStatsInternal(byte[] schemaBytes, byte[]
tableNameBytes, List<PColumn> columns, PTable statsPTable)
+ throws IOException {
+ List<PName> family =
Lists.newArrayListWithExpectedSize(columns.size());
+ for (PColumn column : columns) {
+ PName familyName = column.getFamilyName();
+ if (familyName != null) {
+ family.add(familyName);
+ }
+ }
+ HTable statsHTable = null;
+ try {
+ // Can we do a new HTable instance here? Or get it from a pool
or cache of these instances?
+ statsHTable = new HTable(this.env.getConfiguration(),
+ PhoenixDatabaseMetaData.SYSTEM_STATS_NAME_BYTES);
+ Scan s = new Scan();
+ if (tableNameBytes != null) {
+ // Check for an efficient way here
+ byte[] combinedKey = Bytes.add(Bytes.add(schemaBytes,
QueryConstants.SEPARATOR_BYTE_ARRAY),
--- End diff --
Use SchemaUtil.getTableNameAsBytes(schemaBytes, tableNameBytes)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---