Summary/Reported Issue
CTE failing with NullPointerException but Individual Queries Running
Queries that follow the following format will fail with a NullPointerException error:
with a_query as (
select * from "Samples.samples.dremio.com"."NYC-taxi-trips-iceberg"
),
b_query as (
select * from Samples."samples.dremio.com"."NYC-taxi-trips-iceberg"
)
select * from a_query
The stack trace of the error will be similar to this:
(java.lang.NullPointerException) null
com.dremio.exec.catalog.CachingCatalog.getOrLoadTables():381
com.dremio.exec.catalog.CachingCatalog.bulkGetTablesForQuery():269
com.dremio.exec.ops.TableMetadataPrefetcher.prefetch():160
com.dremio.exec.ops.TableMetadataPrefetcher.<init>():92
com.dremio.exec.ops.TableMetadataPrefetcher$Builder.build():307
com.dremio.exec.ops.IcebergAsyncMetadataRefreshHandler.bulkGetMetadata():291
com.dremio.exec.ops.IcebergAsyncMetadataRefreshHandler.prefetchTableMetadata():112
com.dremio.exec.planner.sql.handlers.EnterpriseNormalHandler.prePlan():58
com.dremio.exec.planner.sql.handlers.query.NormalHandler.getPlan():93
com.dremio.exec.planner.sql.handlers.commands.HandlerToExec.plan():56
com.dremio.exec.work.foreman.AttemptManager.plan():749
com.dremio.exec.work.foreman.AttemptManager.lambda$run$4():584
com.dremio.service.commandpool.ReleasableBoundCommandPool.lambda$getWrappedCommand$1():156
com.dremio.service.commandpool.CommandWrapper.run():73
com.dremio.context.RequestContext.run():103
com.dremio.common.concurrent.ContextMigratingExecutorService.lambda$decorate$4():246
com.dremio.common.concurrent.ContextMigratingExecutorService$ComparableRunnable.run():222
java.util.concurrent.Executors$RunnableAdapter.call():515
java.util.concurrent.FutureTask.run():264
java.util.concurrent.ThreadPoolExecutor.runWorker():1128
java.util.concurrent.ThreadPoolExecutor$Worker.run():628
java.lang.Thread.run():829
Relevant Versions
Dremio 25.2.x
Troubleshooting Steps
Validate that all the queries in your CTE run individually, for example:
select * from "Samples.samples.dremio.com"."NYC-taxi-trips-iceberg";
select * from Samples."samples.dremio.com"."NYC-taxi-trips-iceberg";
Both of these queries should run fine individually.
Cause
This problem is caused by a bug and is reproducible in Dremio 25.2.0.
Steps to Resolve
A patch that fixes this issue was included in Dremio 25.2.2. Upgrade to this version or later to get rid of the problem.