Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing API for collecting Problems in ast to plan conversion #1396

Open
alancai98 opened this issue Mar 21, 2024 · 0 comments
Open

Confusing API for collecting Problems in ast to plan conversion #1396

alancai98 opened this issue Mar 21, 2024 · 0 comments

Comments

@alancai98
Copy link
Member

Currently, the PartiQLPlanner interface has a function called plan that can take a ProblemCallback:

public fun plan(statement: Statement, session: Session, onProblem: ProblemCallback = {}): Result

This is defaulted to a unit if it's not specified in the function call. The function returns a PartiQLPlanner.Result, which has a field for all the Problems:

/**
* Planner result along with any warnings.
*
* @property plan
*/
public class Result(
public val plan: PartiQLPlan,
public val problems: List<Problem>,
)

It can be confusing to the user of the API whether they should check the ProblemCallback that they may pass in or the Result to check if any errors occurred during the ast -> plan transformation. Currently, the default PartiQLPlanner always returns an emptyList():


so checking the PartiQLPlanner.Result for an error does not check anything since it'll always be an empty list.

I came across this issue when our other repo calls the plan function without any ProblemCallback:
https://github.com/partiql/partiql-scribe/blob/f9627257460d28f89201020d096b8f3c94be06ca/src/main/kotlin/org/partiql/scribe/ScribeCompiler.kt#L58-L65

    private fun plan(statement: Statement, session: PartiQLPlanner.Session): PartiQLPlan {
        val result = planner.plan(statement, session)
        val errors = result.problems.filter { it.details.severity == ProblemSeverity.ERROR }
        if (errors.isNotEmpty()) {
            throw RuntimeException("Planner encountered errors: ${errors.joinToString()}")
        }
        return result.plan
    }

The above code does not do any error checking following planning.

Additional Context

  • Java version: 11
  • PartiQL version: 0.14.5-SNAPSHOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant