Skip to content

Commit

Permalink
Fixes PlanTyper bug for paths
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Feb 16, 2024
1 parent 40a065f commit 23c9e26
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5,839 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,43 @@ internal class Env(private val session: PartiQLPlanner.Session) {

/**
* Logic for determining how many BindingNames were “matched” by the ConnectorMetadata
* 1. Matched = RelativePath - Not Found
* 2. Not Found = Input CatalogPath - Output CatalogPath
* 3. Matched = RelativePath - (Input CatalogPath - Output CatalogPath)
* 4. Matched = RelativePath + Output CatalogPath - Input CatalogPath
*
* Assume:
* - steps_matched = user_input_path_size - path_steps_not_found_size
* - path_steps_not_found_size = catalog_path_sent_to_spi_size - actual_catalog_absolute_path_size
*
* Therefore, we present the equation to [calculateMatched]:
* - steps_matched = user_input_path_size - (catalog_path_sent_to_spi_size - actual_catalog_absolute_path_size)
* = user_input_path_size + actual_catalog_absolute_path_size - catalog_path_sent_to_spi_size
*
* For example:
*
* Assume we are in some catalog, C, in some schema, S. There is a tuple, T, with attribute, A1. Assume A1 is of type
* tuple with an attribute A2.
* If our query references `T.A1.A2`, we will eventually ask SPI (connector C) for `S.T.A1.A2`. In this scenario:
* - The original user input was `T.A1.A2` (length 3)
* - The absolute path returned from SPI will be `S.T` (length 2)
* - The path we eventually sent to SPI to resolve was `S.T.A1.A2` (length 4)
*
* So, we can now use [calculateMatched] to determine how many were actually matched from the user input. Using the
* equation from above:
*
* - steps_matched = len(user input) + len(absolute catalog path) - len(path sent to SPI)
* = len([userInputPath]) + len([actualAbsolutePath]) - len([pathSentToConnector])
* = 3 + 2 - 4
* = 5 - 4
* = 1
*
*
* Therefore, in this example we have determined that from the original input (`T.A1.A2`) `T` is the value matched in the
* database environment.
*/
private fun calculateMatched(
originalPath: BindingPath,
inputCatalogPath: BindingPath,
outputCatalogPath: List<String>,
userInputPath: BindingPath,
pathSentToConnector: BindingPath,
actualAbsolutePath: List<String>,
): Int {
return originalPath.steps.size + outputCatalogPath.size - inputCatalogPath.steps.size
return userInputPath.steps.size + actualAbsolutePath.size - pathSentToConnector.steps.size
}

@OptIn(FnExperimental::class, PartiQLValueExperimental::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.partiql.spi.connector.ConnectorHandle
*
* @param T
* @property catalog The resolved entity's catalog name.
* @property input The input binding path that resulted in this item match.
* @property input The input binding path (sent to SPI) that resulted in this item match.
* @property handle The resolved entity's catalog path and type information.
*/
internal data class PathItem<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal abstract class PathResolver<T>(
*/
private fun get(path: BindingPath): PathItem<T>? {
val handle = get(catalog, path) ?: return null
return PathItem(session.currentCatalog, BindingPath(handle.path.steps.map { BindingName(it, BindingCase.SENSITIVE) }), handle)
return PathItem(session.currentCatalog, path, handle)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/partiql-tests-runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tasks.test {
environment(Env.PARTIQL_EQUIV, file("$tests/eval-equiv/").absolutePath)

// To make it possible to run ConformanceTestReport in unit test UI runner, comment out this check:
// exclude("org/partiql/runner/ConformanceTestEval.class", "org/partiql/runner/ConformanceTestLegacy.class")
exclude("org/partiql/runner/ConformanceTestEval.class", "org/partiql/runner/ConformanceTestLegacy.class")

// May 2023: Disabled conformance testing during regular project build, because fail lists are out of date.
exclude("org/partiql/runner/ConformanceTest.class")
Expand Down
Loading

0 comments on commit 23c9e26

Please sign in to comment.