You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/11/23 23:12:59 UTC

[GitHub] [beam] chamikaramj commented on a diff in pull request #24344: Sort SchemaTransform configuration schema fields by name to establish consistency

chamikaramj commented on code in PR #24344:
URL: https://github.com/apache/beam/pull/24344#discussion_r1030932543


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/TypedSchemaTransformProvider.java:
##########
@@ -61,7 +63,13 @@ Optional<List<String>> dependencies(ConfigT configuration, PipelineOptions optio
   @Override
   public final Schema configurationSchema() {
     try {
-      return SchemaRegistry.createDefault().getSchema(configurationClass());
+      Schema schema = SchemaRegistry.createDefault().getSchema(configurationClass());
+
+      // Sort the fields by name to ensure a consistent schema is produced
+      Schema sortedSchema = schema.getFields().stream()
+          .sorted(Comparator.comparing(Field::getName))
+          .collect(Schema.toSchema());

Review Comment:
   Can we also add unit tests  ?



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/TypedSchemaTransformProvider.java:
##########
@@ -61,7 +63,13 @@ Optional<List<String>> dependencies(ConfigT configuration, PipelineOptions optio
   @Override
   public final Schema configurationSchema() {
     try {
-      return SchemaRegistry.createDefault().getSchema(configurationClass());
+      Schema schema = SchemaRegistry.createDefault().getSchema(configurationClass());
+
+      // Sort the fields by name to ensure a consistent schema is produced
+      Schema sortedSchema = schema.getFields().stream()

Review Comment:
   We should also preserve other fields of the Schema, for example, id, options, encoding_positions_set (and any future fields).
   
   https://github.com/apache/beam/blob/master/model/pipeline/src/main/proto/org/apache/beam/model/pipeline/v1/schema.proto#L40



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org