>From Janhavi Tripurwar <[email protected]>:

Janhavi Tripurwar has submitted this change. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20572?usp=email )

Change subject: [ASTERIXDB-3673]: Fix: Prevent CBO failure when samples are 
empty
......................................................................

[ASTERIXDB-3673]: Fix: Prevent CBO failure when samples are empty

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Fallback to RBO when samples are empty.
- Moved issueWarning method to ExceptionUtil for better accessibility.
- Added warning log for visibility.

Ext-ref: MB-69358

Change-Id: Iad996433d22308f8f4096e30a0b04be27c58c020
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20572
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Ali Alsuliman <[email protected]>
Tested-by: Janhavi Tripurwar <[email protected]>
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
M 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/analyze-dataset-1/analyze-dataset-1.1.ddl.sqlpp
M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
M 
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
5 files changed, 29 insertions(+), 14 deletions(-)

Approvals:
  Jenkins: Verified
  Anon. E. Moose #1000171:
  Ali Alsuliman: Looks good to me, approved
  Janhavi Tripurwar: Verified




diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
index d053c19..7aa2e8b 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/EnumerateJoinsRule.java
@@ -32,6 +32,7 @@
 import org.apache.asterix.metadata.declared.DatasetDataSource;
 import org.apache.asterix.metadata.declared.IIndexProvider;
 import org.apache.asterix.metadata.entities.Index;
+import org.apache.asterix.om.exceptions.ExceptionUtil;
 import org.apache.asterix.optimizer.rules.cbo.indexadvisor.AdvisorPlanParser;
 import org.apache.asterix.optimizer.rules.cbo.indexadvisor.CBOPlanStateTree;
 import org.apache.asterix.optimizer.rules.cbo.indexadvisor.FakeIndexProvider;
@@ -1621,8 +1622,15 @@
             if (index == null) {
                 return false;
             }
+            Index.SampleIndexDetails idxDetails = (Index.SampleIndexDetails) 
index.getIndexDetails();
+            double origDatasetCard = idxDetails.getSourceCardinality();
+            if (origDatasetCard == 0) {
+                ExceptionUtil.warnEmptySamples(origDatasetCard, 
scanOp.getSourceLocation(), context);
+                return false;
+            }
             n++;
         }
+
         return (leafInputs.size() == n);
     }

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
index 72ec179..5b567de 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/cbo/Stats.java
@@ -39,6 +39,7 @@
 import org.apache.asterix.om.base.ARecord;
 import org.apache.asterix.om.base.IAObject;
 import org.apache.asterix.om.constants.AsterixConstantValue;
+import org.apache.asterix.om.exceptions.ExceptionUtil;
 import org.apache.asterix.om.functions.BuiltinFunctionInfo;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.optimizer.base.AnalysisUtil;
@@ -638,17 +639,6 @@
         }
     }

-    protected void issueWarning(double sampleCard, DataSourceScanOperator 
scanOp) {
-        if (sampleCard == 0) {
-            sampleCard = 1;
-            IWarningCollector warningCollector = optCtx.getWarningCollector();
-            if (warningCollector.shouldWarn()) {
-                warningCollector.warn(Warning.of(scanOp.getSourceLocation(),
-                        
org.apache.asterix.common.exceptions.ErrorCode.SAMPLE_HAS_ZERO_ROWS));
-            }
-        }
-    }
-
     protected double findSelectivityForThisPredicate(SelectOperator selOp, 
AbstractFunctionCallExpression exp,
             boolean arrayIndex) throws AlgebricksException {
         // replace the SelOp.condition with the new exp and replace it at the 
end
@@ -669,7 +659,7 @@
         Index.SampleIndexDetails idxDetails = (Index.SampleIndexDetails) 
index.getIndexDetails();
         double origDatasetCard = idxDetails.getSourceCardinality();
         double sampleCard = Math.min(idxDetails.getSampleCardinalityTarget(), 
origDatasetCard);
-        issueWarning(sampleCard, scanOp);
+        ExceptionUtil.warnEmptySamples(sampleCard, scanOp.getSourceLocation(), 
optCtx);

         // replace the dataScanSourceOperator with the sampling source
         SampleDataSource sampledatasource = 
joinEnum.getSampleDataSource(scanOp);
@@ -874,7 +864,7 @@
         Index.SampleIndexDetails idxDetails = (Index.SampleIndexDetails) 
index.getIndexDetails();
         double origDatasetCard = idxDetails.getSourceCardinality();
         double sampleCard = Math.min(idxDetails.getSampleCardinalityTarget(), 
origDatasetCard);
-        issueWarning(sampleCard, scanOp);
+        ExceptionUtil.warnEmptySamples(sampleCard, scanOp.getSourceLocation(), 
optCtx);
         return index;
     }

diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/analyze-dataset-1/analyze-dataset-1.1.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/analyze-dataset-1/analyze-dataset-1.1.ddl.sqlpp
index e1d6b10..9e3d85f 100644
--- 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/analyze-dataset-1/analyze-dataset-1.1.ddl.sqlpp
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/analyze-dataset-1/analyze-dataset-1.1.ddl.sqlpp
@@ -21,6 +21,8 @@
  * Description: Test ANALYZE DATASET statement
  */

+// param max-warnings:json=1
+
 set `import-private-functions` `true`;

 drop dataverse test if exists;
@@ -54,3 +56,6 @@
 -- analyze on an empty dataset

 analyze dataset ds1;
+
+-- issue a warning for empty samples
+select * from ds1;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml 
b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
index c157213..f8d415b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
@@ -4302,9 +4302,10 @@
         <output-dir compare="Clean-JSON">create-dataset-4</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="ddl">
+    <test-case FilePath="ddl" check-warnings="true">
       <compilation-unit name="analyze-dataset-1">
         <output-dir compare="Text">analyze-dataset-1</output-dir>
+          <expected-warn>ASX1174: Sample has zero rows</expected-warn>
       </compilation-unit>
     </test-case>
     <test-case FilePath="ddl">
diff --git 
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
 
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
index 24909d7..ebfdb54 100644
--- 
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
+++ 
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
@@ -28,6 +28,7 @@
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.api.context.IEvaluatorContext;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -173,6 +174,16 @@
         }
     }

+    public static void warnEmptySamples(double sampleCard, SourceLocation 
sourceLocation, IOptimizationContext optCtx) {
+        if (sampleCard == 0) {
+            IWarningCollector warningCollector = optCtx.getWarningCollector();
+            if (warningCollector.shouldWarn()) {
+                warningCollector.warn(Warning.of(sourceLocation,
+                        
org.apache.asterix.common.exceptions.ErrorCode.SAMPLE_HAS_ZERO_ROWS));
+            }
+        }
+    }
+
     public static boolean isStringUnicodeError(HyracksDataException throwable) 
{
         return isErrorCode(throwable, INVALID_STRING_UNICODE);
     }

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20572?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Iad996433d22308f8f4096e30a0b04be27c58c020
Gerrit-Change-Number: 20572
Gerrit-PatchSet: 7
Gerrit-Owner: Janhavi Tripurwar <[email protected]>
Gerrit-Reviewer: Ali Alsuliman <[email protected]>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Janhavi Tripurwar <[email protected]>
Gerrit-Reviewer: Jenkins <[email protected]>
Gerrit-Reviewer: Peeyush Gupta <[email protected]>
Gerrit-Reviewer: Preetham Poluparthi <[email protected]>

Reply via email to