sqldelight
sqldelight copied to clipboard
StackOverflowError when compiling recursive query
SQLDelight Version
2.0.1
Operating System
MacOs
Gradle Version
8.4
Kotlin Version
1.9.10
Dialect
Sqlite
AGP Version
8.2.2
Describe the Bug
I am trying to compile the following recursive query:
descendantsOfNode:
WITH RECURSIVE descendants(uuid, depth) AS (
SELECT uuid, 0 AS depth
FROM dmmNodeEntity
WHERE uuid = ?
UNION ALL
SELECT n.uuid, d.depth + 1
FROM dmmNodeEntity n
INNER JOIN descendants d ON n.parent_uuid = d.uuid
)
SELECT * FROM descendants;
I get a StackOverflowError: Cause: java.lang.StackOverflowError at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex$virtualDirectoriesWithDependencies$2.invoke(SqlDelightEnvironment.kt:299)
### Stacktrace
```shell
Cause: java.lang.StackOverflowError
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex$virtualDirectoriesWithDependencies$2.invoke(SqlDelightEnvironment.kt:299)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex$virtualDirectoriesWithDependencies$2.invoke(SqlDelightEnvironment.kt:298)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex.getVirtualDirectoriesWithDependencies(SqlDelightEnvironment.kt:298)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex.sourceFolders(SqlDelightEnvironment.kt:345)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex.sourceFolders(SqlDelightEnvironment.kt:283)
at app.cash.sqldelight.core.SqlDelightFileIndex$DefaultImpls.sourceFolders$default(SqlDelightFileIndex.kt:72)
at app.cash.sqldelight.core.lang.SqlDelightFile.searchScope(SqlDelightFile.kt:71)
at app.cash.sqldelight.core.lang.SqlDelightQueriesFile.searchScope(SqlDelightQueriesFile.kt:161)
at com.alecstrong.sql.psi.core.SqlFileBase.access$searchScope(SqlFileBase.kt:20)
at com.alecstrong.sql.psi.core.SqlFileBase.schema(SqlFileBase.kt:168)
at com.alecstrong.sql.psi.core.psi.mixins.SqlStmtListMixin.tablesAvailable(SqlStmtListMixin.kt:25)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.mixins.WithClauseContainer.tablesAvailable(WithClauseContainer.kt:22)
at com.alecstrong.sql.psi.core.psi.mixins.CompoundSelectStmtMixin.tablesAvailable(CompoundSelectStmtMixin.kt:47)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.mixins.WithClauseContainer.tablesAvailable(WithClauseContainer.kt:22)
at com.alecstrong.sql.psi.core.psi.mixins.CompoundSelectStmtMixin.tablesAvailable(CompoundSelectStmtMixin.kt:47)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlTableReference.getVariants(SqlTableReference.kt:36)
at com.alecstrong.sql.psi.core.psi.SqlTableReference$resolved$1.invoke(SqlTableReference.kt:19)
at com.alecstrong.sql.psi.core.psi.SqlTableReference$resolved$1.invoke(SqlTableReference.kt:16)
at com.alecstrong.sql.psi.core.ModifiableFileLazy.forFile(ModifiableFileLazy.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlTableReference.resolve(SqlTableReference.kt:24)
at com.alecstrong.sql.psi.core.psi.SqlTableReference.resolve(SqlTableReference.kt:11)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables(SelectStmtUtil.kt:58)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables$default(SelectStmtUtil.kt:32)
Gradle Build Script
No response
I have a similar issue with MySQL, SQLDelight Version 2.0.2. I tested the query with Table Plus and it seems fine.
Table:
CREATE TABLE Folder (
id BIGINT NOT NULL AUTO_INCREMENT,
name VARCHAR(64) NOT NULL,
parent_id BIGINT NULL,
PRIMARY KEY (id),
FOREIGN KEY (parent_id) REFERENCES Folder(id)
);
Query:
WITH RECURSIVE ancestor(id, parent_id) AS (
SELECT id, parent_id
FROM Folder
WHERE id = :folder_id
UNION ALL
SELECT f.id, f.parent_id
FROM Folder f
INNER JOIN ancestor a ON a.parent_id = f.id LIMIT 255
)
SELECT * FROM ancestor;
Experiencing a similar issue. SQLDelight v2.0.2 - SQlite dialect.
CREATE TABLE DbFranchise (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
parent_id INTEGER,
country TEXT NOT NULL,
name TEXT NOT NULL,
endpoint_url TEXT NOT NULL,
FOREIGN KEY (parent_id) REFERENCES DbFranchise(id)
);
selectAllWithSubFranchises:
WITH RECURSIVE franchise_tree(id, parent_id, country, name, endpoint_url) AS (
-- Base case
SELECT id, parent_id, country, name, endpoint_url
FROM DbFranchise
WHERE parent_id IS NULL
-- Recursive case
UNION ALL
SELECT f.id, f.parent_id, f.country, f.name, f.endpoint_url
FROM DbFranchise f
INNER JOIN franchise_tree ft ON f.parent_id = ft.id
)
Exception details
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':feature:blue-tag:data:generateCommonMainAppDatabaseInterface'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:148)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:146)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:134)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:331)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:318)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.lambda$execute$0(DefaultTaskExecutionGraph.java:314)
at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:314)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing app.cash.sqldelight.gradle.SqlDelightTask$GenerateInterfaces
at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:283)
at org.gradle.internal.work.DefaultAsyncWorkTracker.lambda$waitForItemsAndGatherFailures$2(DefaultAsyncWorkTracker.java:130)
at org.gradle.internal.Factories$1.create(Factories.java:31)
at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:336)
at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:319)
at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLock(DefaultWorkerLeaseService.java:324)
at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:126)
at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:92)
at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForAll(DefaultAsyncWorkTracker.java:78)
at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:66)
at org.gradle.api.internal.tasks.execution.TaskExecution$3.run(TaskExecution.java:255)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeAction(TaskExecution.java:232)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeActions(TaskExecution.java:215)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeWithPreviousOutputFiles(TaskExecution.java:198)
at org.gradle.api.internal.tasks.execution.TaskExecution.execute(TaskExecution.java:165)
at org.gradle.internal.execution.steps.ExecuteStep.executeInternal(ExecuteStep.java:105)
at org.gradle.internal.execution.steps.ExecuteStep.access$000(ExecuteStep.java:44)
at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:59)
at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:56)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:56)
at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:44)
at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:41)
at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:74)
at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:55)
at org.gradle.internal.execution.steps.PreCreateOutputParentsStep.execute(PreCreateOutputParentsStep.java:50)
at org.gradle.internal.execution.steps.PreCreateOutputParentsStep.execute(PreCreateOutputParentsStep.java:28)
at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:67)
at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:37)
at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:61)
at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:26)
at org.gradle.internal.execution.steps.CaptureOutputsAfterExecutionStep.execute(CaptureOutputsAfterExecutionStep.java:64)
at org.gradle.internal.execution.steps.CaptureOutputsAfterExecutionStep.execute(CaptureOutputsAfterExecutionStep.java:42)
at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:40)
at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:29)
at org.gradle.internal.execution.steps.BuildCacheStep.executeWithoutCache(BuildCacheStep.java:189)
at org.gradle.internal.execution.steps.BuildCacheStep.executeAndStoreInCache(BuildCacheStep.java:145)
at org.gradle.internal.execution.steps.BuildCacheStep.lambda$executeWithCache$4(BuildCacheStep.java:101)
at org.gradle.internal.execution.steps.BuildCacheStep.lambda$executeWithCache$5(BuildCacheStep.java:101)
at org.gradle.internal.Try$Success.map(Try.java:164)
at org.gradle.internal.execution.steps.BuildCacheStep.executeWithCache(BuildCacheStep.java:85)
at org.gradle.internal.execution.steps.BuildCacheStep.lambda$execute$0(BuildCacheStep.java:74)
at org.gradle.internal.Either$Left.fold(Either.java:115)
at org.gradle.internal.execution.caching.CachingState.fold(CachingState.java:59)
at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:73)
at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:48)
at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:44)
at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:33)
at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:76)
at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$2(SkipUpToDateStep.java:54)
at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54)
at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:36)
at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:65)
at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:36)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:37)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:27)
at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:76)
at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:37)
at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:106)
at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:55)
at org.gradle.internal.execution.steps.AbstractCaptureStateBeforeExecutionStep.execute(AbstractCaptureStateBeforeExecutionStep.java:64)
at org.gradle.internal.execution.steps.AbstractCaptureStateBeforeExecutionStep.execute(AbstractCaptureStateBeforeExecutionStep.java:43)
at org.gradle.internal.execution.steps.AbstractSkipEmptyWorkStep.executeWithNonEmptySources(AbstractSkipEmptyWorkStep.java:125)
at org.gradle.internal.execution.steps.AbstractSkipEmptyWorkStep.execute(AbstractSkipEmptyWorkStep.java:61)
at org.gradle.internal.execution.steps.AbstractSkipEmptyWorkStep.execute(AbstractSkipEmptyWorkStep.java:36)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38)
at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:36)
at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:23)
at org.gradle.internal.execution.steps.HandleStaleOutputsStep.execute(HandleStaleOutputsStep.java:75)
at org.gradle.internal.execution.steps.HandleStaleOutputsStep.execute(HandleStaleOutputsStep.java:41)
at org.gradle.internal.execution.steps.AssignMutableWorkspaceStep.lambda$execute$0(AssignMutableWorkspaceStep.java:35)
at org.gradle.api.internal.tasks.execution.TaskExecution$4.withWorkspace(TaskExecution.java:292)
at org.gradle.internal.execution.steps.AssignMutableWorkspaceStep.execute(AssignMutableWorkspaceStep.java:31)
at org.gradle.internal.execution.steps.AssignMutableWorkspaceStep.execute(AssignMutableWorkspaceStep.java:22)
at org.gradle.internal.execution.steps.ChoosePipelineStep.execute(ChoosePipelineStep.java:40)
at org.gradle.internal.execution.steps.ChoosePipelineStep.execute(ChoosePipelineStep.java:23)
at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.lambda$execute$2(ExecuteWorkBuildOperationFiringStep.java:66)
at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.execute(ExecuteWorkBuildOperationFiringStep.java:66)
at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.execute(ExecuteWorkBuildOperationFiringStep.java:38)
at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:36)
at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:26)
at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:47)
at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:34)
at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:61)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:145)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:134)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:331)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:318)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.lambda$execute$0(DefaultTaskExecutionGraph.java:314)
at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:314)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: java.lang.IllegalStateException: Failed to compile SqlCompoundSelectStmtImpl(COMPOUND_SELECT_STMT): [] :
WITH RECURSIVE franchise_tree(id, parent_id, country, name, endpoint_url) AS (
-- Base case
SELECT id, parent_id, country, name, endpoint_url
FROM DbFranchise
WHERE parent_id IS NULL
-- Recursive case
UNION ALL
SELECT f.id, f.parent_id, f.country, f.name, f.endpoint_url
FROM DbFranchise f
INNER JOIN franchise_tree ft ON f.parent_id = ft.id
)
SELECT * FROM franchise_tree
at app.cash.sqldelight.core.compiler.SqlDelightCompilerKt.tryWithElement(SqlDelightCompiler.kt:234)
at app.cash.sqldelight.core.compiler.QueriesTypeGenerator.generateType(QueriesTypeGenerator.kt:55)
at app.cash.sqldelight.core.compiler.SqlDelightCompiler.writeQueries$sqldelight_compiler(SqlDelightCompiler.kt:172)
at app.cash.sqldelight.core.compiler.SqlDelightCompiler.writeInterfaces(SqlDelightCompiler.kt:52)
at app.cash.sqldelight.core.SqlDelightEnvironment$generateSqlDelightFiles$2.invoke(SqlDelightEnvironment.kt:165)
at app.cash.sqldelight.core.SqlDelightEnvironment$generateSqlDelightFiles$2.invoke(SqlDelightEnvironment.kt:156)
at app.cash.sqldelight.core.SqlDelightEnvironment$forSourceFiles$1.invoke(SqlDelightEnvironment.kt:125)
at app.cash.sqldelight.core.SqlDelightEnvironment$forSourceFiles$1.invoke(SqlDelightEnvironment.kt:120)
at com.alecstrong.sql.psi.core.SqlCoreEnvironment.forSourceFiles$lambda$2(SqlCoreEnvironment.kt:171)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContentUnderDirectory(SqlCoreEnvironment.kt:228)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContentUnderDirectory(SqlCoreEnvironment.kt:225)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContentUnderDirectory(SqlCoreEnvironment.kt:225)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContentUnderDirectory(SqlCoreEnvironment.kt:225)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContentUnderDirectory(SqlCoreEnvironment.kt:225)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContentUnderDirectory(SqlCoreEnvironment.kt:225)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContentUnderDirectory(SqlCoreEnvironment.kt:225)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContentUnderDirectory(SqlCoreEnvironment.kt:225)
at com.alecstrong.sql.psi.core.CoreFileIndex.iterateContent(SqlCoreEnvironment.kt:219)
at com.alecstrong.sql.psi.core.SqlCoreEnvironment.forSourceFiles(SqlCoreEnvironment.kt:168)
at app.cash.sqldelight.core.SqlDelightEnvironment.forSourceFiles(SqlDelightEnvironment.kt:120)
at app.cash.sqldelight.core.SqlDelightEnvironment.forSqlFileBases(SqlDelightEnvironment.kt:366)
at app.cash.sqldelight.core.SqlDelightEnvironment.generateSqlDelightFiles(SqlDelightEnvironment.kt:156)
at app.cash.sqldelight.gradle.SqlDelightTask$GenerateInterfaces.execute(SqlDelightTask.kt:98)
at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:54)
at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:48)
at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:48)
at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:49)
at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:30)
at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:96)
at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:65)
at org.gradle.process.internal.worker.request.WorkerAction$1.call(WorkerAction.java:146)
at org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)
at org.gradle.process.internal.worker.request.WorkerAction.lambda$run$0(WorkerAction.java:143)
at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80)
at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:135)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: java.lang.StackOverflowError
at com.intellij.openapi.vfs.local.CoreLocalFileSystem.findFileByNioFile(CoreLocalFileSystem.java:26)
at com.intellij.openapi.vfs.local.CoreLocalFileSystem.findFileByPath(CoreLocalFileSystem.java:31)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex$virtualDirectoriesWithDependencies$2.invoke(SqlDelightEnvironment.kt:300)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex$virtualDirectoriesWithDependencies$2.invoke(SqlDelightEnvironment.kt:298)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex.getVirtualDirectoriesWithDependencies(SqlDelightEnvironment.kt:298)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex.sourceFolders(SqlDelightEnvironment.kt:345)
at app.cash.sqldelight.core.SqlDelightEnvironment$FileIndex.sourceFolders(SqlDelightEnvironment.kt:283)
at app.cash.sqldelight.core.SqlDelightFileIndex$DefaultImpls.sourceFolders$default(SqlDelightFileIndex.kt:72)
at app.cash.sqldelight.core.lang.SqlDelightFile.searchScope(SqlDelightFile.kt:71)
at app.cash.sqldelight.core.lang.SqlDelightQueriesFile.searchScope(SqlDelightQueriesFile.kt:161)
at com.alecstrong.sql.psi.core.SqlFileBase.access$searchScope(SqlFileBase.kt:20)
at com.alecstrong.sql.psi.core.SqlFileBase.schema(SqlFileBase.kt:168)
at com.alecstrong.sql.psi.core.psi.mixins.SqlStmtListMixin.tablesAvailable(SqlStmtListMixin.kt:25)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.mixins.WithClauseContainer.tablesAvailable(WithClauseContainer.kt:22)
at com.alecstrong.sql.psi.core.psi.mixins.CompoundSelectStmtMixin.tablesAvailable(CompoundSelectStmtMixin.kt:47)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.mixins.WithClauseContainer.tablesAvailable(WithClauseContainer.kt:22)
at com.alecstrong.sql.psi.core.psi.mixins.CompoundSelectStmtMixin.tablesAvailable(CompoundSelectStmtMixin.kt:47)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl.tablesAvailable(SqlCompositeElementImpl.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlTableReference.getVariants(SqlTableReference.kt:36)
at com.alecstrong.sql.psi.core.psi.SqlTableReference$resolved$1.invoke(SqlTableReference.kt:19)
at com.alecstrong.sql.psi.core.psi.SqlTableReference$resolved$1.invoke(SqlTableReference.kt:16)
at com.alecstrong.sql.psi.core.ModifiableFileLazy.forFile(ModifiableFileLazy.kt:22)
at com.alecstrong.sql.psi.core.psi.SqlTableReference.resolve(SqlTableReference.kt:24)
at com.alecstrong.sql.psi.core.psi.SqlTableReference.resolve(SqlTableReference.kt:11)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables(SelectStmtUtil.kt:58)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables$default(SelectStmtUtil.kt:32)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables(SelectStmtUtil.kt:36)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.tablesObserved(SelectStmtUtil.kt:29)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables(SelectStmtUtil.kt:55)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables$default(SelectStmtUtil.kt:32)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables(SelectStmtUtil.kt:58)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables$default(SelectStmtUtil.kt:32)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables(SelectStmtUtil.kt:36)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.tablesObserved(SelectStmtUtil.kt:29)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables(SelectStmtUtil.kt:55)
at app.cash.sqldelight.core.lang.util.SelectStmtUtilKt.referencedTables$default(SelectStmtUtil.kt:32)
... Repeats from here ...
@slickorange I've had your same issue with a similar case. I fixed it out of luck by removing the alias from the recursive CTE on the INNER JOIN
block.
In your specific use case, I've removed the alias ...INNER JOIN descendants d...
by leaving only ...INNER JOIN descendants...
, and replacing every d
alias occurrence with the recursive CTE full name.
And it also seems to be also the cases of @Qubiz and @jschnall, but I haven't tried the solution on their samples yet.
Hope it can be a useful clue to help maintainers solve the issue.
Full example here (compiled with SQLite 3.18.x compiler):
-- dmmNodeEntity.sq
CREATE TABLE `dmmNodeEntity` (
`uuid` TEXT NOT NULL PRIMARY KEY,
`parent_uuid` TEXT
REFERENCES `dmmNodeEntity`(`uuid`)
ON DELETE CASCADE
ON UPDATE CASCADE
);
insert:
INSERT INTO `dmmNodeEntity`(`uuid`, `parent_uuid`) VALUES (:uuid, :parentUuid);
descendantsOfNode:
WITH RECURSIVE descendants(uuid, depth) AS (
SELECT uuid, 0 AS depth
FROM dmmNodeEntity
WHERE uuid = ?
UNION ALL
SELECT n.uuid, descendants.depth + 1
FROM dmmNodeEntity n
INNER JOIN descendants ON n.parent_uuid = descendants.uuid
)
SELECT * FROM descendants;
@slickorange I've had your same issue with a similar case. I fixed it out of luck by removing the alias from the recursive CTE on the
INNER JOIN
block.In your specific use case, I've removed the alias
...INNER JOIN descendants d...
by leaving only...INNER JOIN descendants...
, and replacing everyd
alias occurrence with the recursive CTE full name.And it also seems to be also the cases of @Qubiz and @jschnall, but I haven't tried the solution on their samples yet.
Hope it can be a useful clue to help maintainers solve the issue.
Full example here (compiled with SQLite 3.18.x compiler):
-- dmmNodeEntity.sq CREATE TABLE `dmmNodeEntity` ( `uuid` TEXT NOT NULL PRIMARY KEY, `parent_uuid` TEXT REFERENCES `dmmNodeEntity`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE ); insert: INSERT INTO `dmmNodeEntity`(`uuid`, `parent_uuid`) VALUES (:uuid, :parentUuid); descendantsOfNode: WITH RECURSIVE descendants(uuid, depth) AS ( SELECT uuid, 0 AS depth FROM dmmNodeEntity WHERE uuid = ? UNION ALL SELECT n.uuid, descendants.depth + 1 FROM dmmNodeEntity n INNER JOIN descendants ON n.parent_uuid = descendants.uuid ) SELECT * FROM descendants;
Thanks @razvanred - this solved it for me!