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

Annotations can be dropped in some circumstances #2

Open
raganhan opened this issue May 17, 2019 · 1 comment
Open

Annotations can be dropped in some circumstances #2

raganhan opened this issue May 17, 2019 · 1 comment
Labels
bug Something isn't working M Medium sized task

Comments

@raganhan
Copy link
Contributor

To reproduce, place this test in org]partiql/eval/NodeMetadataLookupTest.kt

    @Test
    fun withStructPreservesAnnotations() {
        val astWithMeta = """
            ((meta (lit [f::[a::b::{x:c::1,y:2,z:e::a}]]) {line:1,column:23}))
        """.sexp()

        val (ast, lookup) = NodeMetadataLookup.extractMetaNode(astWithMeta)

        with(lookup) {
            assertEquals("((lit [f::[a::b::{x:c::1,y:2,z:e::a}]]))", ast.toString())
            assertMetadata(null, ast)

            assertEquals("(lit [f::[a::b::{x:c::1,y:2,z:e::a}]])", ast[0].toString())
            assertMetadata(NodeMetadata(1, 23), ast[0])

            val sexp = ast[0] as IonSexp
            val str = ((sexp[1] as IonList)[0] as IonList)[0] as IonStruct
            assertNotNull(str.typeAnnotationSymbols)
        }
    }
@therapon therapon added bug Something isn't working M Medium sized task S Small sized task and removed M Medium sized task labels Feb 13, 2020
@raganhan raganhan added M Medium sized task and removed S Small sized task labels Feb 14, 2020
@raganhan
Copy link
Contributor Author

Changing size to M since it'd be good to add more test coverage for values with annotations

@raganhan raganhan removed their assignment Feb 14, 2020
dlurton added a commit that referenced this issue Mar 15, 2021
#2, adds CompilerPipeline interface and makes EvaluatingCompiler internal.
vgapeyev added a commit that referenced this issue Mar 27, 2023
johnedquinn added a commit that referenced this issue Oct 12, 2023
am357 added a commit that referenced this issue Jul 26, 2024
```SQL
CREATE TABLE PETS (
    id INT4,
    breed STRING,
    tag INT2
)
```

Tests:
```SQL
-- #1 should succeed
CAST(true AS INT2) --

-- #2  should fail
CAST((s : STRING) AS LIST)

-- #3 should succeed
CAST((i : INT2) AS INT4)

-- #4 should succeed
CAST((i : INT4) AS INT2)
```

#### Background context
As part of a specification work, we want to make the behavior for the #4 more visible:

 From SQL-99 Section 6.22: <cast specification>:

```
 If SD (source data type) is exact numeric or approximate numeric, then
 Case:
   i) If there is a representation of SV (source value) in the data type TD (target data type) that does not lose any leading si-gnificant digits after rounding or truncating if necessary, then TV is that representation.
 The choice of whether to round or truncate is implementation-defined.
 ii) Otherwise, an exception condition is raised: data exception — numeric value out of
 range.
 ```

We can see this evaluation behavior in PostgresSQL v15:
Ref.: https://www.db-fiddle.com/f/vMY3Srd2bG6f3NshvTp3w1/0

```
-- succeeds
SELECT CAST((1::INT4) AS INT2);

-- fails: `Query Error: error: smallint out of range`
SELECT CAST((327686::INT4) AS INT2);
```
am357 added a commit that referenced this issue Jul 29, 2024
Add more cast tests

```SQL
CREATE TABLE PETS (
    id INT4,
    breed STRING,
    tag INT2
)
```

Tests:
```SQL
-- #1 should succeed
CAST(true AS INT2) --

-- #2  should fail
CAST((s : STRING) AS LIST)

-- #3 should succeed
CAST((i : INT2) AS INT4)

-- #4 should succeed
CAST((i : INT4) AS INT2)
```

#### Background context
As part of a specification work, we want to make the behavior for the #4 more visible:

 From SQL-99 Section 6.22: <cast specification>:

```
 If SD (source data type) is exact numeric or approximate numeric, then
 Case:
   i) If there is a representation of SV (source value) in the data type TD (target data type) that does not lose any leading si-gnificant digits after rounding or truncating if necessary, then TV is that representation.
 The choice of whether to round or truncate is implementation-defined.
 ii) Otherwise, an exception condition is raised: data exception — numeric value out of
 range.
 ```

We can see this evaluation behavior in PostgresSQL v15:
Ref.: https://www.db-fiddle.com/f/vMY3Srd2bG6f3NshvTp3w1/0

```
-- succeeds
SELECT CAST((1::INT4) AS INT2);

-- fails: `Query Error: error: smallint out of range`
SELECT CAST((327686::INT4) AS INT2);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working M Medium sized task
Projects
None yet
Development

No branches or pull requests

2 participants