This is an automated email from the ASF dual-hosted git repository. vlsi pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/calcite.git
commit f6184bdad7cd9c71a4662d41ac38d7f927233647 Author: Vladimir Sitnikov <[email protected]> AuthorDate: Wed Nov 18 22:57:48 2026 +0300 [CALCITE-7949] Throw UnsupportedOperationException when a PigTable is scanned PigTable has a row type and no rows, and PigTable.scan returned null. Executing a plan that scans one, such as the plan for "A = LOAD 'testSchema.testTable' as (a:int, b:chararray);", failed with java.lang.NullPointerException: Cannot invoke "org.apache.calcite.linq4j.Enumerable.select(org.apache.calcite.linq4j.function.Function1)" because "enumerable" is null User-visible: Executing such a plan fails with UnsupportedOperationException: PigTable has a row type and no rows; it cannot be scanned. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- .../main/java/org/apache/calcite/piglet/PigTable.java | 3 ++- .../test/java/org/apache/calcite/test/PigRelOpTest.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/piglet/src/main/java/org/apache/calcite/piglet/PigTable.java b/piglet/src/main/java/org/apache/calcite/piglet/PigTable.java index 94a8f7427f..a00b2199a0 100644 --- a/piglet/src/main/java/org/apache/calcite/piglet/PigTable.java +++ b/piglet/src/main/java/org/apache/calcite/piglet/PigTable.java @@ -71,6 +71,7 @@ public static RelOptTable createRelOptTable(RelOptSchema schema, } @Override public Enumerable<@Nullable Object[]> scan(final DataContext root) { - return null; + throw new UnsupportedOperationException( + "PigTable has a row type and no rows; it cannot be scanned"); } } diff --git a/piglet/src/test/java/org/apache/calcite/test/PigRelOpTest.java b/piglet/src/test/java/org/apache/calcite/test/PigRelOpTest.java index e1c60c10cb..0c3a2db13e 100644 --- a/piglet/src/test/java/org/apache/calcite/test/PigRelOpTest.java +++ b/piglet/src/test/java/org/apache/calcite/test/PigRelOpTest.java @@ -19,9 +19,12 @@ import org.apache.calcite.rel.RelNode; import org.apache.calcite.sql.SqlDialect; import org.apache.calcite.sql.dialect.CalciteSqlDialect; +import org.apache.calcite.tools.RelRunners; import org.apache.calcite.util.TestUtil; import org.apache.calcite.util.Util; +import com.google.common.base.Throwables; + import org.hamcrest.Matcher; import org.junit.jupiter.api.Test; @@ -37,8 +40,10 @@ import static org.apache.calcite.test.Matchers.hasTree; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Tests for {@code PigRelOpVisitor}. @@ -206,6 +211,17 @@ private Fluent pig(String script) { .assertRel(hasTree("LogicalTableScan(table=[[scott, DEPT]])\n")); } + /** A table loaded with a Pig schema has a row type and no rows to read. */ + @Test void testExecuteLoadWithSchema() throws IOException { + final RelNode rel = + converter.pigQuery2Rel("A = LOAD 'testSchema.testTable' as (a:int, b:chararray);") + .get(0); + final Throwable e = + assertThrows(Throwable.class, () -> RelRunners.run(rel).executeQuery()); + assertThat(Throwables.getRootCause(e), + instanceOf(UnsupportedOperationException.class)); + } + @Test void testFilter() { final String script = "" + "A = LOAD 'scott.DEPT' as (DEPTNO:int, DNAME:chararray, LOC:CHARARRAY);\n"
