pri1712 commented on code in PR #19011:
URL: https://github.com/apache/pinot/pull/19011#discussion_r3657628667


##########
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java:
##########
@@ -480,4 +496,110 @@ protected void onQueryFinish(long requestId) {
   protected boolean isQueryCancellationEnabled() {
     return _enableQueryCancellation;
   }
+
+  /**
+   * Appends a where clause to the query to filter out of retention data if 
SKIP_OUT_OF_RETENTION_VALUES is
+   * set to True in query Options.
+   * @param sqlNodeAndOptions
+   */
+  private void applySkipOutOfRetentionValuesIfNeeded(SqlNodeAndOptions 
sqlNodeAndOptions) {
+    Map<String, String> options = sqlNodeAndOptions.getOptions();
+    if 
(!Boolean.parseBoolean(options.get(QueryOptionKey.SKIP_OUT_OF_RETENTION_VALUES)))
 {
+      return;
+    }
+
+    SqlNode sqlNode = sqlNodeAndOptions.getSqlNode();
+    if (sqlNode == null) {
+      return;
+    }
+
+    // Resolve the inner SqlSelect, unwrapping SqlOrderBy if needed.
+    // SqlWith (CTEs) and other statement types are not supported.
+    SqlSelect sqlSelect;
+    if (sqlNode instanceof SqlSelect) {
+      sqlSelect = (SqlSelect) sqlNode;
+    } else if (sqlNode instanceof SqlOrderBy) {
+      SqlNode query = ((SqlOrderBy) sqlNode).query;
+      if (!(query instanceof SqlSelect)) {
+        return;
+      }
+      sqlSelect = (SqlSelect) query;
+    } else {
+      return;
+    }
+
+    TableNameExtractor tableNameExtractor = new TableNameExtractor();
+    tableNameExtractor.extractTableNames(sqlSelect);
+    Set<String> tableNames = tableNameExtractor.getTableNames();
+    if (tableNames.isEmpty()) {
+      return;
+    }
+
+    // Multi-table queries (JOINs) are not supported: it is ambiguous which 
table's retention
+    // applies, and injecting a filter with the wrong table's time column 
would produce
+    // incorrect results. Callers must issue separate single-table queries.
+    if (tableNames.size() > 1) {
+      LOGGER.debug("skipOutOfRetentionValues is not supported for multi-table 
queries; skipping filter injection");
+      return;
+    }
+
+    String rawTableName = 
TableNameBuilder.extractRawTableName(tableNames.iterator().next());
+
+    TableConfig tableConfig = _tableCache.getTableConfig(rawTableName);
+    Schema schema = _tableCache.getSchema(rawTableName);
+    if (tableConfig == null || schema == null || 
tableConfig.getValidationConfig() == null) {
+      return;
+    }
+
+    //get timestamp column and retention details
+    String timeColumnName = 
tableConfig.getValidationConfig().getTimeColumnName();
+    String retentionTimeUnit = 
tableConfig.getValidationConfig().getRetentionTimeUnit();
+    String retentionTimeValue = 
tableConfig.getValidationConfig().getRetentionTimeValue();
+    if (StringUtils.isEmpty(timeColumnName) || 
StringUtils.isEmpty(retentionTimeUnit)
+        || StringUtils.isEmpty(retentionTimeValue)) {
+      return;
+    }
+    try {
+      long retentionTimeMs =

Review Comment:
   ack



-- 
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]

Reply via email to