Skip to content

Commit 52d24ed

Browse files
committed
Fix SQL generator's -cc option to be effective with Collection
1 parent 69dc2c9 commit 52d24ed

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,11 @@ private String processComplexType( final ComplexType entity, final Context conte
297297

298298
if ( type instanceof Scalar ) {
299299
final String typeDef = type.accept( this, context );
300-
columns.append( column( columnPrefix, typeDef, property.isOptional(),
301-
Optional.ofNullable( property.getDescription( config.commentLanguage() ) ) ) )
300+
final Optional<String> comment = config.includeColumnComments()
301+
? Optional.ofNullable( Optional.ofNullable( context.forceDescriptionFromElement() ).orElse( property )
302+
.getDescription( config.commentLanguage() ) )
303+
: Optional.empty();
304+
columns.append( column( columnPrefix, typeDef, property.isOptional(), comment) )
302305
.append( lineDelimiter );
303306
} else if ( type instanceof ComplexType ) {
304307
columns.append( processComplexType( type.as( ComplexType.class ), context, columnPrefix, type.is( DefaultList.class ) ) );

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,26 @@ void testDatabricksGeneration( final TestAspect testAspect ) {
4848
assertThat( result ).doesNotContain( "ARRAY<ARRAY" );
4949
} ).doesNotThrowAnyException();
5050
}
51+
52+
@ParameterizedTest
53+
@EnumSource( value = TestAspect.class )
54+
void testDatabricksGenerationExcludeComments( final TestAspect testAspect ) {
55+
final Aspect aspect = TestResources.load( testAspect ).aspect();
56+
assertThatCode( () -> {
57+
final DatabricksSqlGenerationConfig dialectSpecificConfig = DatabricksSqlGenerationConfigBuilder.builder()
58+
.includeTableComment( false )
59+
.includeColumnComments( false )
60+
.commentLanguage( Locale.ENGLISH )
61+
.build();
62+
final SqlArtifact sqlArtifact = new AspectModelSqlGenerator( aspect, SqlGenerationConfigBuilder.builder()
63+
.dialect( SqlGenerationConfig.Dialect.DATABRICKS )
64+
.dialectSpecificConfig( dialectSpecificConfig )
65+
.build() ).singleResult();
66+
final String result = sqlArtifact.getContent();
67+
68+
assertThat( result ).contains( "TBLPROPERTIES ('x-samm-aspect-model-urn'='" );
69+
assertThat( result ).doesNotContain( "ARRAY<ARRAY" );
70+
assertThat( result ).doesNotContain( "COMMENT" );
71+
} ).doesNotThrowAnyException();
72+
}
5173
}

0 commit comments

Comments
 (0)