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

Fix Build and unit test in PartiQL SPI merge #1361

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 35 additions & 36 deletions partiql-cli/src/test/kotlin/org/partiql/cli/functions/PowTest.kt
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@

package org.partiql.cli.functions

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.partiql.cli.makeCliAndGetResult
import org.partiql.cli.pipeline.AbstractPipeline
import org.partiql.cli.utils.ServiceLoaderUtil
import java.nio.file.Paths

/**
* Class `PowTest` is used to test the 'test_power' function, which calculates the base to the power of exponent.
* It is a plugin mockdb functions loaded by Java Service Loader.
*
* @property pipeline Creates a pipeline using service loaded functions. It allows to process a stream of records.
*
* @constructor Creates an instance of `PowTest`.
*/
@Disabled
class PowTest {

val pluginPath = Paths.get(System.getProperty("testingPluginDirectory"))

private val pipeline = AbstractPipeline.create(
AbstractPipeline.PipelineOptions(
functions = ServiceLoaderUtil.loadFunctions(pluginPath)
)
)

@Test
fun PowTest() {
val result = makeCliAndGetResult(query = "test_power(2,3)", pipeline = pipeline)
assertEquals(8.0, result.toDouble())
}
}
//
// package org.partiql.cli.functions
//
// import org.junit.jupiter.api.Assertions.assertEquals
// import org.junit.jupiter.api.Disabled
// import org.junit.jupiter.api.Test
// import org.partiql.cli.makeCliAndGetResult
// import org.partiql.cli.pipeline.AbstractPipeline
// import java.nio.file.Paths
//
// /**
// * Class `PowTest` is used to test the 'test_power' function, which calculates the base to the power of exponent.
// * It is a plugin mockdb functions loaded by Java Service Loader.
// *
// * @property pipeline Creates a pipeline using service loaded functions. It allows to process a stream of records.
// *
// * @constructor Creates an instance of `PowTest`.
// */
// @Disabled
// class PowTest {
//
// val pluginPath = Paths.get(System.getProperty("testingPluginDirectory"))
//
// private val pipeline = AbstractPipeline.create(
// AbstractPipeline.PipelineOptions(
// functions = ServiceLoaderUtil.loadFunctions(pluginPath)
// )
// )
//
// @Test
// fun PowTest() {
// val result = makeCliAndGetResult(query = "test_power(2,3)", pipeline = pipeline)
// assertEquals(8.0, result.toDouble())
// }
// }
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@

package org.partiql.cli.functions

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.partiql.cli.makeCliAndGetResult
import org.partiql.cli.pipeline.AbstractPipeline
import org.partiql.cli.utils.ServiceLoaderUtil
import java.nio.file.Paths

/**
* Class `TrimLeadTest` is used to test the 'trim_lead' function, which is used to trim the leading whitespace characters
* from the string it processes. It is a plugin mockdb functions loaded by Java Service Loader.
*
* @property pipeline Creates a pipeline using service loaded functions. It allows to process a stream of records.
*
* @constructor Creates an instance of `TrimLeadTest`.
*/
@Disabled
class TrimLeadTest {

val pluginPath = Paths.get(System.getProperty("testingPluginDirectory"))

private val pipeline = AbstractPipeline.create(
AbstractPipeline.PipelineOptions(
functions = ServiceLoaderUtil.loadFunctions(pluginPath)
)
)

@Test
fun TrimTest() {
val input = "' hello'"
val expected = "\"hello\""

val result = makeCliAndGetResult(query = "trim_lead($input)", pipeline = pipeline)

assertEquals(expected, result.trim())
}
}
//
// package org.partiql.cli.functions
//
// import org.junit.jupiter.api.Assertions.assertEquals
// import org.junit.jupiter.api.Disabled
// import org.junit.jupiter.api.Test
// import org.partiql.cli.makeCliAndGetResult
// import org.partiql.cli.pipeline.AbstractPipeline
// import org.partiql.cli.utils.ServiceLoaderUtil
// import java.nio.file.Paths
//
// /**
// * Class `TrimLeadTest` is used to test the 'trim_lead' function, which is used to trim the leading whitespace characters
// * from the string it processes. It is a plugin mockdb functions loaded by Java Service Loader.
// *
// * @property pipeline Creates a pipeline using service loaded functions. It allows to process a stream of records.
// *
// * @constructor Creates an instance of `TrimLeadTest`.
// */
// @Disabled
// class TrimLeadTest {
//
// val pluginPath = Paths.get(System.getProperty("testingPluginDirectory"))
//
// private val pipeline = AbstractPipeline.create(
// AbstractPipeline.PipelineOptions(
// functions = ServiceLoaderUtil.loadFunctions(pluginPath)
// )
// )
//
// @Test
// fun TrimTest() {
// val input = "' hello'"
// val expected = "\"hello\""
//
// val result = makeCliAndGetResult(query = "trim_lead($input)", pipeline = pipeline)
//
// assertEquals(expected, result.trim())
// }
// }
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.partiql.cli.utils.ServiceLoaderUtil
import org.partiql.lang.eval.ExprFunction
import java.nio.file.Paths

@Disabled
class ServiceLoaderUtilTest {
@Test
fun `loadPlugins loads the correct plugins`() {

val pluginPath = Paths.get(System.getProperty("testingPluginDirectory"))
val functions: List<ExprFunction> = ServiceLoaderUtil.loadFunctions(pluginPath)

assertTrue(functions.map { it.signature.name }.contains("trim_lead"))
assertTrue(functions.map { it.signature.name }.contains("test_power"))
}
}
//
// import org.junit.jupiter.api.Assertions.assertTrue
// import org.junit.jupiter.api.Disabled
// import org.junit.jupiter.api.Test
// import org.partiql.cli.utils.ServiceLoaderUtil
// import org.partiql.lang.eval.ExprFunction
// import java.nio.file.Paths
//
// @Disabled
// class ServiceLoaderUtilTest {
// @Test
// fun `loadPlugins loads the correct plugins`() {
//
// val pluginPath = Paths.get(System.getProperty("testingPluginDirectory"))
// val functions: List<ExprFunction> = ServiceLoaderUtil.loadFunctions(pluginPath)
//
// assertTrue(functions.map { it.signature.name }.contains("trim_lead"))
// assertTrue(functions.map { it.signature.name }.contains("test_power"))
// }
// }
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import org.partiql.eval.PartiQLResult
import org.partiql.parser.PartiQLParser
import org.partiql.planner.PartiQLPlanner
import org.partiql.planner.PartiQLPlannerBuilder
import org.partiql.plugin.PartiQLPlugin
import org.partiql.spi.function.PartiQLFunctionExperimental
import org.partiql.plugins.memory.MemoryCatalog
import org.partiql.plugins.memory.MemoryConnector
import org.partiql.spi.connector.ConnectorSession
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.bagValue
Expand Down Expand Up @@ -453,20 +454,26 @@ class PartiQLEngineDefaultTest {
val mode: PartiQLEngine.Mode = PartiQLEngine.Mode.PERMISSIVE
) {

@OptIn(PartiQLFunctionExperimental::class)
private val engine = PartiQLEngine.builder().build()
private val planner = PartiQLPlannerBuilder().build()
private val parser = PartiQLParser.default()

@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
internal fun assert() {
val statement = parser.parse(input).root
val session = PartiQLPlanner.Session("q", "u")
val plan = planner.plan(statement, session)
val functions = mapOf(
"partiql" to PartiQLPlugin.functions
val catalog = MemoryCatalog.builder().name("memory").build()
val connector = MemoryConnector(catalog)
val connectorSession = object : ConnectorSession {
override fun getQueryId(): String = "q"
override fun getUserId(): String = "u"
}
val session = PartiQLPlanner.Session(
"q",
"u",
"memory",
catalogs = mapOf("memory" to connector.getMetadata(connectorSession))
)
val prepared = engine.prepare(plan.plan, PartiQLEngine.Session(functions = functions, mode = mode))
val plan = planner.plan(statement, session)
val prepared = engine.prepare(plan.plan, PartiQLEngine.Session(mapOf("memory" to connector), mode = mode))
val result = engine.execute(prepared) as PartiQLResult.Value
val output = result.value
assertEquals(expected, output, comparisonString(expected, output))
Expand Down Expand Up @@ -496,12 +503,10 @@ class PartiQLEngineDefaultTest {
val expectedPermissive: PartiQLValue
) {

@OptIn(PartiQLFunctionExperimental::class)
private val engine = PartiQLEngine.builder().build()
private val planner = PartiQLPlannerBuilder().build()
private val parser = PartiQLParser.default()

@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
internal fun assert() {
val permissiveResult = run(mode = PartiQLEngine.Mode.PERMISSIVE)
assertEquals(expectedPermissive, permissiveResult, comparisonString(expectedPermissive, permissiveResult))
Expand All @@ -514,15 +519,22 @@ class PartiQLEngineDefaultTest {
assertNotNull(error)
}

@OptIn(PartiQLFunctionExperimental::class)
private fun run(mode: PartiQLEngine.Mode): PartiQLValue {
val statement = parser.parse(input).root
val session = PartiQLPlanner.Session("q", "u")
val plan = planner.plan(statement, session)
val functions = mapOf(
"partiql" to PartiQLPlugin.functions
val catalog = MemoryCatalog.builder().name("memory").build()
val connector = MemoryConnector(catalog)
val connectorSession = object : ConnectorSession {
override fun getQueryId(): String = "q"
override fun getUserId(): String = "u"
}
val session = PartiQLPlanner.Session(
"q",
"u",
"memory",
catalogs = mapOf("memory" to connector.getMetadata(connectorSession))
)
val prepared = engine.prepare(plan.plan, PartiQLEngine.Session(functions = functions, mode = mode))
val plan = planner.plan(statement, session)
val prepared = engine.prepare(plan.plan, PartiQLEngine.Session(mapOf("memory" to connector), mode = mode))
when (val result = engine.execute(prepared)) {
is PartiQLResult.Value -> return result.value
is PartiQLResult.Error -> throw result.cause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ internal class CastTable private constructor(
}
graph[ANY] = ANY.relationships {
coercion(ANY)
PartiQLValueType.values().filterNot { it == ANY }.forEach {
unsafe(it)
}
}
graph[NULL] = NULL.relationships {
coercion(NULL)
Expand Down
Loading
Loading