Skip to content

Commit

Permalink
Add tests for Ion's typed nulls (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 authored Jul 28, 2023
1 parent 3ceb168 commit c580925
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.partiql.lang.eval

import com.amazon.ion.IonSystem
import com.amazon.ion.system.IonSystemBuilder
import org.junit.Test
import org.partiql.lang.CompilerPipeline

/**
* The following tests demonstrate the current typed null behavior and tracks possible regressions in future commits.
* This behavior is what the Kotlin implementation defines and is subject to change pending resolution of
* https://github.com/partiql/partiql-spec/issues/61.
*/
class TypedNullTests : EvaluatorTestBase() {
// Round-tripped typed nulls (IonValue -> ExprValue -> IonValue) results in same typed null value
@Test
fun typedNullIonValueExprValueRoundTrip() {
val ion: IonSystem = IonSystemBuilder.standard().build()
val ionValue = ion.singleValue("null.int")
val exprValue = ExprValue.of(ionValue)
val roundTripped = exprValue.toIonValue(ion)
assertEquals(ionValue, roundTripped)
}

// Evaluated typed nulls converted to an IonValue preserve the typed null.
@Test
fun typedNullIonLiteralEvaluation() {
val pipeline = CompilerPipeline.standard()
val ionValueAsString = "null.int"
val expr = pipeline.compile("`$ionValueAsString`")
val session = EvaluationSession.standard()
val result = expr.eval(session)
val ionValueRoundtripped = result.toIonValue(ion)
assertEquals(ion.singleValue(ionValueAsString), ionValueRoundtripped)
}

// Evaluated typed nulls in an SFW projection. Converting result to an IonValue preserves the typed null.
@Test
fun typedNullInSFW() {
val pipeline = CompilerPipeline.standard()
val expr = pipeline.compile("SELECT t.a FROM [{'a': `null.int`}] AS t")
val session = EvaluationSession.standard()
val result = expr.eval(session)
val ionValueRoundtripped = result.toIonValue(ion)
assertEquals(ion.singleValue("\$bag::[{a: null.int}]"), ionValueRoundtripped)
}

// Evaluated typed nulls in an arithmetic expression will NOT preserve the type when converting back to IonValue.
@Test
fun typedNullInArithmeticOperation() {
val pipeline = CompilerPipeline.standard()
val expr = pipeline.compile("`null.int` + `null.int`")
val session = EvaluationSession.standard()
val result = expr.eval(session)
val ionValueRoundtripped = result.toIonValue(ion)
assertEquals(ion.singleValue("null"), ionValueRoundtripped)
}
}

1 comment on commit c580925

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JMH Benchmark

Benchmark suite Current: c580925 Previous: 3ceb168 Ratio
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLCompiler15 122.05493607311249 us/op 179.36948160391643 us/op 0.68
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLCompiler30 234.29145538849357 us/op 395.32692704927916 us/op 0.59
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator15 451416.7675916667 us/op 594068.3074 us/op 0.76
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator30 1039896.2575 us/op 1116918.99835 us/op 0.93
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator30WithData10 10467659.807500001 us/op 11200307.3889 us/op 0.93
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLParser15 189.514053242577 us/op 248.32620909009628 us/op 0.76
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLParser30 379.17309851691573 us/op 485.7572023208039 us/op 0.78
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameCaseWhenThen 46.127625361692125 us/op 80.40577800924878 us/op 0.57
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery 63.22506589098462 us/op 91.59307064706026 us/op 0.69
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery01 315.49890013365786 us/op 458.9099344396042 us/op 0.69
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery02 549.7708447699017 us/op 747.1327009431432 us/op 0.74
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameExceptUnionIntersectSixty 215.4475671559751 us/op 292.3742689597752 us/op 0.74
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameExec20Expressions 68.88502136324108 us/op 104.24032907224039 us/op 0.66
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameFromLet 48.49314863524876 us/op 83.93179545902805 us/op 0.58
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGraphPattern 48.62248081644734 us/op 78.66738795415063 us/op 0.62
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGraphPreFilters 75.884645518122 us/op 131.3816760914659 us/op 0.58
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGroupLimit 49.690954334276306 us/op 91.64691341714969 us/op 0.54
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameLongFromSourceOrderBy 70.08263933846999 us/op 102.50367278559592 us/op 0.68
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameManyJoins 68.83532072586334 us/op 113.89178590874783 us/op 0.60
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameNestedAggregates 119.5659725452906 us/op 183.08778691509545 us/op 0.65
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameNestedParen 22.153789705836946 us/op 34.859077858322124 us/op 0.64
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNamePivot 72.03602506402245 us/op 119.93769601656213 us/op 0.60
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuery15OrsAndLikes 222.80173119495709 us/op 361.79161031081065 us/op 0.62
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuery30Plus 122.83779610359367 us/op 169.31291085427546 us/op 0.73
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryFunc 55.26646379375201 us/op 84.1577931905553 us/op 0.66
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryFuncInProjection 127.62861558151126 us/op 181.18625184256842 us/op 0.70
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryList 82.75994516917672 us/op 124.42108512640755 us/op 0.67
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryNestedSelect 780.9349864574201 us/op 1033.3210688093604 us/op 0.76
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuerySimple 19.911621791320393 us/op 30.81793269869154 us/op 0.65
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralJoins 25.985980954042496 us/op 43.05898089577538 us/op 0.60
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralProjections 75.51335653019405 us/op 120.30467485786502 us/op 0.63
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralSelect 220.1614959150611 us/op 325.4621894085254 us/op 0.68
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSimpleInsert 33.89818650073466 us/op 60.26623457896085 us/op 0.56
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeJoins 25.66619565724137 us/op 40.8656316265531 us/op 0.63
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeProjections 33.99708957422836 us/op 54.73938812263408 us/op 0.62
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeSelect 57.91553709495038 us/op 90.8796850550864 us/op 0.64
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameTimeZone 29.461197455565475 us/op 46.06846290614983 us/op 0.64
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameVeryLongQuery 362.8578449373355 us/op 493.71907697882773 us/op 0.73
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameVeryLongQuery01 1096.0161856678683 us/op 1503.2544534622325 us/op 0.73
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameCaseWhenThen 28.789034876155473 us/op 41.16143856682594 us/op 0.70
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameComplexQuery 263.29804194647033 us/op 363.5105488484568 us/op 0.72
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameComplexQuery01 117.3161058068857 us/op 168.170863990143 us/op 0.70
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameExceptUnionIntersectSixty 237.85250070347934 us/op 295.1048271781815 us/op 0.81
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameExec20Expressions 72.46652149895019 us/op 101.64657321993901 us/op 0.71
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameFromLet 41.34411639752328 us/op 63.6972659693944 us/op 0.65
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGraphPattern 44.613931628234276 us/op 68.90532098358224 us/op 0.65
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGraphPreFilters 74.70424574405331 us/op 107.12351596822225 us/op 0.70
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGroupLimit 36.59936835634586 us/op 63.712288285439726 us/op 0.57
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameLongFromSourceOrderBy 140.9092505591318 us/op 200.41056743103465 us/op 0.70
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameManyJoins 47.774983696005705 us/op 70.8224072765803 us/op 0.67
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameNestedAggregates 100.20897610812993 us/op 143.12300286006337 us/op 0.70
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameNestedParen 92.54327135753516 us/op 111.59063341178985 us/op 0.83
org.partiql.jmh.benchmarks.ParserBenchmark.parseNamePivot 68.90421183375268 us/op 98.58712535914779 us/op 0.70
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuery15OrsAndLikes 185.29223122475574 us/op 246.5652179610832 us/op 0.75
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuery30Plus 68.29906460197033 us/op 85.32059913024739 us/op 0.80
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryFunc 137.82306114374745 us/op 213.65445513598428 us/op 0.65
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryFuncInProjection 103.24264900192398 us/op 126.41918307060811 us/op 0.82
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryList 88.33082671978244 us/op 110.99149891463341 us/op 0.80
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryNestedSelect 145.81853948540015 us/op 210.90218509966104 us/op 0.69
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuerySimple 15.025943891534116 us/op 21.438112720633786 us/op 0.70
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralJoins 79.43087412252149 us/op 106.89775872669527 us/op 0.74
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralProjections 62.85038504691122 us/op 83.0535139336651 us/op 0.76
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralSelect 119.24319942559444 us/op 155.76221343829758 us/op 0.77
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSimpleInsert 24.00261805940456 us/op 37.08539752665267 us/op 0.65
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeJoins 23.818668609471402 us/op 34.841857786877014 us/op 0.68
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeProjections 20.817881434513247 us/op 30.473554981228357 us/op 0.68
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeSelect 38.558339950480594 us/op 51.05844109763021 us/op 0.76
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameTimeZone 10.535186129194543 us/op 15.635037906924794 us/op 0.67
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameVeryLongQuery 451.7669226339449 us/op 578.9377567028818 us/op 0.78
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameVeryLongQuery01 1288.53918961447 us/op 1510.5870572394736 us/op 0.85
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLCompiler 9.757357606645877 us/op 14.673620588849014 us/op 0.66
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLEvaluator 2.5599806883641723 us/op 2.9099337459729337 us/op 0.88
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLParser 13.16577834859251 us/op 20.191156365983797 us/op 0.65

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.