apache / apache/beam

SELECT COALESCE(...) isn't inferred as non-nullable field

Open
#19,730 1 comment 0 reactions 0 assignees View on GitHub
bug dsl P3 sql
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

In Calcite, Coalesce is described as:

```

ReturnTypes.cascade(ReturnTypes.LEAST_RESTRICTIVE,
SqlTypeTransforms.LEAST_NULLABLE)

```

However, giving non-null constant as an argument doesn't result in a non-nullable expression:

```

Schema inputSchema = Schema.of(
Schema.Field.of("name", Schema.FieldType.STRING.withNullable(true)));

PCollection input = p.apply(Create.of(ImmutableList.of())
.withCoder(SchemaCoder.of(inputSchema)));

Schema outputSchema = input
.apply(SqlTransform.query("SELECT COALESCE(name, 'unknown')
as name FROM PCOLLECTION"))
.getSchema();

assertEquals(
Schema.builder().addStringField("name").build(),

outputSchema);

```

Not sure if it's a problem in Calcite or Beam SQL.

There are no other functions that can be used to produce a non-nullable field.

Imported from Jira [BEAM-7610](https://issues.apache.org/jira/browse/BEAM-7610). Original Jira may contain additional context.
Reported by: kanterov.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.