jackjlli commented on a change in pull request #3568: Add guava cache to cache 
table schema in pinot broker
URL: https://github.com/apache/incubator-pinot/pull/3568#discussion_r254907522
 
 

 ##########
 File path: 
pinot-broker/src/main/java/com/linkedin/pinot/broker/requesthandler/BaseBrokerRequestHandler.java
 ##########
 @@ -311,6 +329,68 @@ private void validateRequest(BrokerRequest brokerRequest) 
{
             "Value for 'LIMIT' (" + limit + ") exceeds maximum allowed value 
of " + _queryResponseLimit);
       }
     }
+
+    // Checks whether the query contains non-existence columns.
+    // Table name has already been verified before hitting this line.
+    String tableName = brokerRequest.getQuerySource().getTableName();
+    Schema schema = _tableSchemaCache.getIfTableSchemaPresent(tableName);
+    if (schema != null) {
+      Set<String> allColumns = getAllColumnsFromBrokerRequest(brokerRequest);
+      Set<String> copied = new HashSet<>(allColumns);
+      copied.removeAll(schema.getColumnNames());
+      if (!copied.isEmpty()) {
+        _brokerMetrics.addMeteredTableValue(tableName, 
BrokerMeter.QUERY_NON_EXISTENCE_COLUMNS, 1L);
+        throw new RuntimeException("Found non-existence columns from the 
query: " + copied.toString());
+      }
+    } else {
+      // If the cache doesn't have the schema, loads the schema to the cache 
asynchronously.
+      _tableSchemaCache.refreshTableSchema(tableName);
+    }
+  }
+
+  /**
+   * Helper to get all the columns from broker request.
+   * Returns the set of all the columns.
+   */
+  private Set<String> getAllColumnsFromBrokerRequest(BrokerRequest 
brokerRequest) {
+    Set<String> allColumns = new HashSet<>();
+    // Filter
+    FilterQueryTree filterQueryTree = 
RequestUtils.generateFilterQueryTree(brokerRequest);
 
 Review comment:
   Talked with @mayankshriv offline. It's better we parse the query only once 
end-to-end, i.e from broker to server. While this might need to have another 
design on changing the payload, which would be out of the scope of this PR. In 
the current PR we guarantee the query is parsed only once in pinot-broker. We 
can take this payload change in the near future.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pinot.apache.org
For additional commands, e-mail: dev-h...@pinot.apache.org

Reply via email to