@@ -36,6 +36,7 @@ public class SnowflakeBatchSourceConfig extends BaseSnowflakeConfig {
36
36
public static final String PROPERTY_MAX_SPLIT_SIZE = "maxSplitSize" ;
37
37
public static final String PROPERTY_SCHEMA = "schema" ;
38
38
public static final String PROPERTY_TABLE_NAME = "tableName" ;
39
+ public static final String PROPERTY_IMPORT_QUERY_TYPE = "importQueryType" ;
39
40
40
41
@ Name (PROPERTY_REFERENCE_NAME )
41
42
@ Description ("This will be used to uniquely identify this source/sink for lineage, annotating metadata, etc." )
@@ -65,11 +66,11 @@ public class SnowflakeBatchSourceConfig extends BaseSnowflakeConfig {
65
66
@ Nullable
66
67
private final String tableName ;
67
68
68
- @ Name ("importQueryType" )
69
+ @ Name (PROPERTY_IMPORT_QUERY_TYPE )
69
70
@ Description ("Whether to select Table Name or Import Query to extract the data." )
70
71
@ Macro
71
72
@ Nullable
72
- private final ImportQueryType importQueryType ;
73
+ private final String importQueryType ;
73
74
74
75
75
76
public SnowflakeBatchSourceConfig (String referenceName , String accountName , String database ,
@@ -81,7 +82,7 @@ public SnowflakeBatchSourceConfig(String referenceName, String accountName, Stri
81
82
@ Nullable String connectionArguments ,
82
83
@ Nullable String schema ,
83
84
@ Nullable String tableName ,
84
- @ Nullable ImportQueryType importQueryType ) {
85
+ @ Nullable String importQueryType ) {
85
86
super (
86
87
accountName , database , schemaName , username , password , keyPairEnabled , path , passphrase ,
87
88
oauth2Enabled , clientId , clientSecret , refreshToken , connectionArguments
@@ -91,7 +92,7 @@ public SnowflakeBatchSourceConfig(String referenceName, String accountName, Stri
91
92
this .maxSplitSize = maxSplitSize ;
92
93
this .schema = schema ;
93
94
this .tableName = tableName ;
94
- this .importQueryType = importQueryType ;
95
+ this .importQueryType = getImportQueryType () ;
95
96
}
96
97
97
98
public String getImportQuery () {
@@ -117,8 +118,8 @@ public String getTableName() {
117
118
}
118
119
119
120
@ Nullable
120
- public ImportQueryType getImportQueryType () {
121
- return importQueryType == null ? ImportQueryType .IMPORT_QUERY : importQueryType ;
121
+ public String getImportQueryType () {
122
+ return importQueryType == null ? ImportQueryType .IMPORT_QUERY . name () : importQueryType ;
122
123
}
123
124
124
125
public void validate (FailureCollector collector ) {
@@ -130,10 +131,27 @@ public void validate(FailureCollector collector) {
130
131
.withConfigProperty (PROPERTY_MAX_SPLIT_SIZE );
131
132
}
132
133
133
- if (Strings .isNullOrEmpty (importQuery ) && Strings .isNullOrEmpty (tableName )) {
134
- collector .addFailure ("Either 'Schema' or 'Table Name' must be provided." , null )
135
- .withConfigProperty (PROPERTY_IMPORT_QUERY )
136
- .withConfigProperty (PROPERTY_TABLE_NAME );
134
+ if (!containsMacro (PROPERTY_IMPORT_QUERY_TYPE )) {
135
+ boolean isImportQuerySelected = ImportQueryType .IMPORT_QUERY .getValue ().equals (importQueryType );
136
+ boolean isTableNameSelected = ImportQueryType .TABLE_NAME .getValue ().equals (importQueryType );
137
+
138
+ if (isImportQuerySelected && !containsMacro (PROPERTY_IMPORT_QUERY ) && Strings .isNullOrEmpty (importQuery )) {
139
+ collector .addFailure ("Import Query cannot be empty" , null )
140
+ .withConfigProperty (PROPERTY_IMPORT_QUERY );
141
+
142
+ } else if (isTableNameSelected && !containsMacro (PROPERTY_TABLE_NAME ) && Strings .isNullOrEmpty (tableName )) {
143
+ collector .addFailure ("Table Name cannot be empty" , null )
144
+ .withConfigProperty (PROPERTY_TABLE_NAME );
145
+ }
146
+ } else {
147
+ boolean isImportQueryMissing = !containsMacro (PROPERTY_IMPORT_QUERY ) && Strings .isNullOrEmpty (importQuery );
148
+ boolean isTableNameMissing = !containsMacro (PROPERTY_TABLE_NAME ) && Strings .isNullOrEmpty (tableName );
149
+
150
+ if (isImportQueryMissing && isTableNameMissing ) {
151
+ collector .addFailure ("Either 'Import Query' or 'Table Name' must be provided." , null )
152
+ .withConfigProperty (PROPERTY_IMPORT_QUERY )
153
+ .withConfigProperty (PROPERTY_TABLE_NAME );
154
+ }
137
155
}
138
156
}
139
157
}
0 commit comments