-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generates a partiql prelude for PLK (#1490)
- Loading branch information
Showing
49 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
= Builtins | ||
|
||
See https://github.com/orgs/partiql/discussions/64 | ||
|
||
== Syntax | ||
|
||
``` | ||
{ | ||
name: <symbol>, // the routine name | ||
type: op|fn|agg, // the routine type | ||
description: ''' | ||
I am a multi-line string for generated documentation.. | ||
''', | ||
impls: [ | ||
(fn name::type -> type), // start with op|fn|agg followed by name annotated arg types, then -> <return type> | ||
.... | ||
] | ||
} | ||
``` |
14 changes: 14 additions & 0 deletions
14
partiql-planner/src/main/resources/builtins/other/fn_cardinality.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
name: cardinality, | ||
type: fn, | ||
description:''' | ||
Placeholder for `cardinality` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn container::bag -> int), | ||
(fn container::list -> int), | ||
(fn container::sexp -> int), | ||
(fn container::struct -> int) | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
partiql-planner/src/main/resources/builtins/other/fn_date_add.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
name: date_add, | ||
type: fn, | ||
description:''' | ||
Placeholder for `date_add` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn part::string interval::int datetime::date -> date), | ||
(fn part::string interval::int datetime::time -> time), | ||
(fn part::string interval::int datetime::timestamp -> timestamp), | ||
(fn part::string interval::interval datetime::date -> date), | ||
(fn part::string interval::interval datetime::time -> time), | ||
(fn part::string interval::interval datetime::timestamp -> timestamp), | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
partiql-planner/src/main/resources/builtins/other/fn_date_diff.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
name: date_diff, | ||
type: fn, | ||
description:''' | ||
Placeholder for `date_diff` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn part::string interval::int datetime::date -> date), | ||
(fn part::string interval::int datetime::time -> time), | ||
(fn part::string interval::int datetime::timestamp -> timestamp), | ||
(fn part::string interval::interval datetime::date -> date), | ||
(fn part::string interval::interval datetime::time -> time), | ||
(fn part::string interval::interval datetime::timestamp -> timestamp), | ||
] | ||
} |
Empty file.
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/partiql/fn_coll_any.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: coll_any, | ||
type: fn, | ||
description:''' | ||
Placeholder for `coll_any` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn collection::bag -> bool), | ||
(fn collection::list -> bool), | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/partiql/fn_coll_avg.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: coll_avg, | ||
type: fn, | ||
description:''' | ||
Placeholder for `coll_avg` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn collection::bag -> dynamic), | ||
(fn collection::list -> dynamic), | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/partiql/fn_coll_count.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: coll_count, | ||
type: fn, | ||
description:''' | ||
Placeholder for `coll_count` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn collection::bag -> dynamic), | ||
(fn collection::list -> dynamic), | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/partiql/fn_coll_every.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: coll_every, | ||
type: fn, | ||
description:''' | ||
Placeholder for `coll_every` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn collection::bag -> bool), | ||
(fn collection::list -> bool), | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/partiql/fn_coll_max.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: coll_max, | ||
type: fn, | ||
description:''' | ||
Placeholder for `coll_max` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn value::bag -> dynamic), | ||
(fn value::list -> dynamic), | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/partiql/fn_coll_min.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: coll_min, | ||
type: fn, | ||
description:''' | ||
Placeholder for `coll_min` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn value::bag -> dynamic), | ||
(fn value::list -> dynamic), | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/partiql/fn_coll_some.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: coll_some, | ||
type: fn, | ||
description:''' | ||
Placeholder for `coll_some` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn collection::bag -> bool), | ||
(fn collection::list -> bool), | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/partiql/fn_coll_sum.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: coll_sum, | ||
type: fn, | ||
description:''' | ||
Placeholder for `coll_sum` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(fn value::bag -> dynamic), | ||
(fn value::list -> dynamic) | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
partiql-planner/src/main/resources/builtins/sql99/agg_any.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
name: any, | ||
type: agg, | ||
description:''' | ||
Placeholder for `any` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(agg value::bool -> bool), | ||
] | ||
} |
18 changes: 18 additions & 0 deletions
18
partiql-planner/src/main/resources/builtins/sql99/agg_avg.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
name: avg, | ||
type: agg, | ||
description:''' | ||
Placeholder for `avg` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(agg value::tinyint -> tinyint), | ||
(agg value::smallint -> smallint), | ||
(agg value::int -> int), | ||
(agg value::bigint -> bigint), | ||
(agg value::numeric -> numeric), | ||
(agg value::decimal -> decimal), | ||
(agg value::real -> real), | ||
(agg value::double -> double), | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
partiql-planner/src/main/resources/builtins/sql99/agg_count.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
name: count, | ||
type: agg, | ||
description:''' | ||
Placeholder for `count` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(agg -> int), // COUNT(*) | ||
(agg value::dynamic -> int), | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
partiql-planner/src/main/resources/builtins/sql99/agg_every.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
name: every, | ||
type: agg, | ||
description:''' | ||
Placeholder for `every` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(agg value::bool -> bool), | ||
] | ||
} |
18 changes: 18 additions & 0 deletions
18
partiql-planner/src/main/resources/builtins/sql99/agg_max.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
name: max, | ||
type: agg, | ||
description:''' | ||
Placeholder for `max` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(agg value::tinyint -> tinyint), | ||
(agg value::smallint -> smallint), | ||
(agg value::int -> int), | ||
(agg value::bigint -> bigint), | ||
(agg value::numeric -> numeric), | ||
(agg value::decimal -> decimal), | ||
(agg value::real -> real), | ||
(agg value::double -> double), | ||
] | ||
} |
18 changes: 18 additions & 0 deletions
18
partiql-planner/src/main/resources/builtins/sql99/agg_min.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
name: min, | ||
type: agg, | ||
description:''' | ||
Placeholder for `min` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(agg value::tinyint -> tinyint), | ||
(agg value::smallint -> smallint), | ||
(agg value::int -> int), | ||
(agg value::bigint -> bigint), | ||
(agg value::numeric -> numeric), | ||
(agg value::decimal -> decimal), | ||
(agg value::real -> real), | ||
(agg value::double -> double), | ||
] | ||
} |
18 changes: 18 additions & 0 deletions
18
partiql-planner/src/main/resources/builtins/sql99/agg_sum.ion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
name: sum, | ||
type: agg, | ||
description:''' | ||
Placeholder for `sum` description | ||
''', | ||
properties: [], | ||
impls: [ | ||
(agg value::tinyint -> numeric), | ||
(agg value::smallint -> numeric), | ||
(agg value::int -> numeric), | ||
(agg value::bigint -> numeric), | ||
(agg value::numeric -> numeric), | ||
(agg value::decimal -> decimal), | ||
(agg value::real -> double), | ||
(agg value::double -> double), | ||
] | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
77 changes: 77 additions & 0 deletions
77
partiql-spi/src/test/kotlin/org/partiql/spi/connector/sql/SqlBuiltinsDump.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.partiql.spi.connector.sql | ||
|
||
import com.amazon.ion.system.IonTextWriterBuilder | ||
import com.amazon.ionelement.api.IonElement | ||
import com.amazon.ionelement.api.SymbolElement | ||
import com.amazon.ionelement.api.ionListOf | ||
import com.amazon.ionelement.api.ionSexpOf | ||
import com.amazon.ionelement.api.ionString | ||
import com.amazon.ionelement.api.ionStructOf | ||
import com.amazon.ionelement.api.ionSymbol | ||
import org.junit.jupiter.api.Test | ||
import org.partiql.spi.fn.FnExperimental | ||
import org.partiql.spi.fn.FnSignature | ||
import org.partiql.types.PType | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
import kotlin.io.path.outputStream | ||
|
||
@OptIn(FnExperimental::class) | ||
class SqlBuiltinsDump { | ||
|
||
private val HOME = System.getProperty("user.home") | ||
private val DEST = Paths.get(HOME, "Desktop", "builtins") | ||
|
||
@Test | ||
fun getBuiltins() { | ||
Files.deleteIfExists(DEST) | ||
Files.createDirectories(DEST) | ||
val map = SqlBuiltins.builtins.groupBy( | ||
keySelector = { it.signature.name }, | ||
valueTransform = { it.signature }, | ||
) | ||
for ((name, signatures) in map) { | ||
val file = Files.createFile(DEST.resolve("$name.ion")) | ||
val fields = mutableListOf<Pair<String, IonElement>>() | ||
val writer = IonTextWriterBuilder | ||
.pretty() | ||
.build(file.outputStream()) | ||
fields.add("name" to ionSymbol(name)) | ||
fields.add("type" to ionSymbol("fn")) | ||
fields.add("description" to ionString("\nPlaceholder for $name description\n")) | ||
fields.add("properties" to ionListOf()) | ||
fields.add("impls" to ionListOf(signatures.map { it.toIon() })) | ||
val definition = ionStructOf(*fields.toTypedArray()) | ||
definition.writeTo(writer) | ||
} | ||
} | ||
|
||
// private fun header(fn: FnSignature) = buildString { | ||
// appendLine("/*") | ||
// append(fn.sql()) | ||
// appendLine("*/") | ||
// } | ||
|
||
private fun FnSignature.toIon(): IonElement { | ||
val elements = mutableListOf<IonElement>() | ||
elements.add(ionSymbol("fn")) | ||
for (p in parameters) { | ||
val t = p.type.toIon() | ||
elements.add(t.withAnnotations(p.name)) | ||
} | ||
elements.add(ionSymbol("->")) | ||
elements.add(returns.toIon()) | ||
return ionSexpOf(elements) | ||
} | ||
|
||
private fun PType.toIon(): SymbolElement { | ||
val text = when (kind) { | ||
PType.Kind.INT_ARBITRARY -> "numeric" | ||
PType.Kind.DECIMAL_ARBITRARY -> "decimal" | ||
PType.Kind.DOUBLE_PRECISION -> "double" | ||
PType.Kind.ROW -> "struct" | ||
else -> kind.name.lowercase() | ||
} | ||
return ionSymbol(text) | ||
} | ||
} |