Skip to content

Commit 74c3d0f

Browse files
authored
Merge pull request #657 from bci-oss/bugfix/605-error-creating-delta-table-with-the-generated-schema
Error creating delta table with the generated schema
2 parents 89e96f5 + ab20503 commit 74c3d0f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/sql/databricks/AspectModelDatabricksDenormalizedSqlVisitor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ public String visitCollection( final Collection collection, final Context contex
257257
.getDescription( config.commentLanguage() ) )
258258
: Optional.empty();
259259
final String typeDef = type.isComplexType()
260-
? entityToStruct( type.as( ComplexType.class ) ).toString()
260+
? entityToStruct( type.as( ComplexType.class ), false ).toString()
261261
: type.accept( this, context );
262262
return column( context.prefix(), "ARRAY<" + typeDef + ">", property.isOptional() || context.forceOptional(),
263263
comment );
264264
}
265265

266-
private DatabricksType.DatabricksStruct entityToStruct( final ComplexType entity ) {
266+
private DatabricksType.DatabricksStruct entityToStruct( final ComplexType entity, final boolean isInsideNestedType ) {
267267
return new DatabricksType.DatabricksStruct( entity.getAllProperties().stream()
268268
.flatMap( property -> {
269269
if ( property.getDataType().isEmpty() || property.isNotInPayload() ) {
@@ -274,12 +274,15 @@ private DatabricksType.DatabricksStruct entityToStruct( final ComplexType entity
274274
if ( type instanceof final Scalar scalar ) {
275275
databricksType = databricksTypeMap.get( scalar.getUrn() );
276276
} else if ( type instanceof final Entity entityType ) {
277-
databricksType = entityToStruct( entityType );
277+
databricksType = entityToStruct( entityType, true );
278278
} else {
279279
return Stream.empty();
280280
}
281+
282+
boolean isOptional = isInsideNestedType || property.isOptional();
283+
281284
return Stream.of( new DatabricksType.DatabricksStructEntry( columnName( property ), databricksType,
282-
property.isOptional(), Optional.ofNullable( property.getDescription( config.commentLanguage() ) ) ) );
285+
isOptional, Optional.ofNullable( property.getDescription( config.commentLanguage() ) ) ) );
283286
} )
284287
.toList() );
285288
}

core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/sql/databricks/AspectModelDatabricksDenormalizedSqlVisitorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.junit.jupiter.api.Test;
2525

2626
@SuppressWarnings( "checkstyle:LineLength" )
27-
public class AspectModelDatabricksDenormalizedSqlVisitorTest extends DatabricksTestBase {
27+
class AspectModelDatabricksDenormalizedSqlVisitorTest extends DatabricksTestBase {
2828
@Test
2929
void testAspectWithAbstractEntity() {
3030
assertThat( sql( TestAspect.ASPECT_WITH_ABSTRACT_ENTITY ) ).isEqualTo( """
@@ -319,7 +319,7 @@ CREATE TABLE IF NOT EXISTS aspect_with_multiple_entity_collections (
319319
void testAspectWithNestedEntityList() {
320320
assertThat( sql( TestAspect.ASPECT_WITH_NESTED_ENTITY_LIST ) ).isEqualTo( """
321321
CREATE TABLE IF NOT EXISTS aspect_with_nested_entity_list (
322-
test_list ARRAY<STRUCT<test_string: STRING NOT NULL, test_int: INT NOT NULL, test_float: FLOAT NOT NULL, test_second_list: STRUCT<test_local_date_time: TIMESTAMP NOT NULL, random_value: STRING NOT NULL> NOT NULL>> NOT NULL
322+
test_list ARRAY<STRUCT<test_string: STRING NOT NULL, test_int: INT NOT NULL, test_float: FLOAT NOT NULL, test_second_list: STRUCT<test_local_date_time: TIMESTAMP, random_value: STRING> NOT NULL>> NOT NULL
323323
)
324324
TBLPROPERTIES ('x-samm-aspect-model-urn'='urn:samm:org.eclipse.esmf.test:1.0.0#AspectWithNestedEntityList');
325325
""" );

0 commit comments

Comments
 (0)