Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-7610

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

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2
    • Resolution: Unresolved
    • Affects Version/s: 2.13.0
    • Fix Version/s: None
    • Component/s: dsl-sql
    • Labels:
      None

      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<Row> input = p.apply(Create.of(ImmutableList.<Row>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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                kanterov Gleb Kanterov
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: