siddharthteotia commented on a change in pull request #4983: Make PQL case 
insensitive
URL: https://github.com/apache/incubator-pinot/pull/4983#discussion_r366670882
 
 

 ##########
 File path: 
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java
 ##########
 @@ -335,6 +349,74 @@ public BrokerResponse handleRequest(JsonNode request, 
@Nullable RequesterIdentit
     return brokerResponse;
   }
 
+  private void handleCaseSensitivity(BrokerRequest brokerRequest) {
+    String inputTableName = brokerRequest.getQuerySource().getTableName();
+    String actualTableName = _tableCache.getActualTableName(inputTableName);
+    brokerRequest.getQuerySource().setTableName(actualTableName);
+    //fix columns
+    if (brokerRequest.getFilterSubQueryMap() != null) {
+      Collection<FilterQuery> values = 
brokerRequest.getFilterSubQueryMap().getFilterQueryMap().values();
+      for (FilterQuery filterQuery : values) {
+        if (filterQuery.getNestedFilterQueryIdsSize() == 0) {
+          String expression = filterQuery.getColumn();
+          filterQuery.setColumn(fixColumnNameCase(actualTableName, 
expression));
+        }
+      }
+    }
+    if (brokerRequest.isSetAggregationsInfo()) {
+      for (AggregationInfo info : brokerRequest.getAggregationsInfo()) {
+        if (info.getAggregationParams() != null && !info.getAggregationType()
+            .equalsIgnoreCase(AggregationFunctionType.COUNT.getName())) {
+          String column = 
info.getAggregationParams().get(FunctionCallAstNode.COLUMN_KEY_IN_AGGREGATION_INFO);
+          String[] expressions = 
column.split(FunctionCallAstNode.DISTINCT_MULTI_COLUMN_SEPARATOR);
+          String[] newExpressions = new String[expressions.length];
+          for (int i = 0; i < expressions.length; i++) {
+            String expression = expressions[i];
+            newExpressions[i] = fixColumnNameCase(actualTableName, expression);
+          }
+          String newColumns = 
StringUtil.join(FunctionCallAstNode.DISTINCT_MULTI_COLUMN_SEPARATOR, 
newExpressions);
+          
info.getAggregationParams().put(FunctionCallAstNode.COLUMN_KEY_IN_AGGREGATION_INFO,
 newColumns);
+        }
+      }
+      if (brokerRequest.isSetGroupBy()) {
+        List<String> expressions = brokerRequest.getGroupBy().getExpressions();
+        for (int i = 0; i < expressions.size(); i++) {
+          expressions.set(i, fixColumnNameCase(actualTableName, 
expressions.get(i)));
+        }
+      }
+    } else {
+      Selection selection = brokerRequest.getSelections();
+      List<String> selectionColumns = selection.getSelectionColumns();
+      for (int i = 0; i < selectionColumns.size(); i++) {
+        String expression = selectionColumns.get(i);
+        if (!expression.trim().equalsIgnoreCase("*")) {
+          selectionColumns.set(i, fixColumnNameCase(actualTableName, 
expression));
+        }
+      }
+    }
+  }
+
+  private String fixColumnNameCase(String actualTableName, String expression) {
+    TransformExpressionTree rootExpression = 
TransformExpressionTree.compileToExpressionTree(expression);
+    LinkedList<TransformExpressionTree> q = new LinkedList<>();
+    q.add(rootExpression);
+    while (!q.isEmpty()) {
+      TransformExpressionTree expressionTree = q.pop();
+      switch (expressionTree.getExpressionType()) {
+        case FUNCTION:
 
 Review comment:
   We should recurse for FUNCTION expression to identify the inner column names 
(IDENTIFIERS) at the leaf level and fix case for them

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to