Skip to content

Commit

Permalink
fix build issue and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yliuuuu committed Feb 3, 2024
1 parent 9a32af9 commit 3aa96fa
Show file tree
Hide file tree
Showing 34 changed files with 225 additions and 182 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -1151,11 +1151,11 @@ internal class PlanTyper(
}
}

// True iff NULL CALL and had a NULL arg; or NOT missable and had MISSING argument
val isNull = (fn.isNullCall && hadNull) || (!fn.isMissable && hadMissing)
// True iff NULL CALL and had a NULL arg;
val isNull = (fn.isNullCall && hadNull)

// True iff NULL CALL and had a NULLABLE arg; or is a NULLABLE operator
val isNullable = (fn.isNullCall && hadNullable) || fn.isNullable || (!fn.isMissable && hadMissable)
val isNullable = (fn.isNullCall && hadNullable) || fn.isNullable

// True iff MISSING CALL and had a MISSING arg.
val isMissing = fn.isMissingCall && hadMissing
Expand All @@ -1165,6 +1165,7 @@ internal class PlanTyper(

// Return type with calculated nullability
var type: StaticType = when {
isMissing -> MISSING
isNull -> NULL
isNullable -> fn.returns.toStaticType()
else -> fn.returns.toNonNullStaticType()
Expand Down
Loading

0 comments on commit 3aa96fa

Please sign in to comment.