39
39
import static io .airbyte .integrations .source .postgres .xmin .XminCtidUtils .reclassifyCategorisedCtidStreams ;
40
40
import static java .util .stream .Collectors .toList ;
41
41
import static java .util .stream .Collectors .toSet ;
42
- import static org .postgresql .PGProperty .ADAPTIVE_FETCH ;
43
- import static org .postgresql .PGProperty .CURRENT_SCHEMA ;
44
- import static org .postgresql .PGProperty .DEFAULT_ROW_FETCH_SIZE ;
45
- import static org .postgresql .PGProperty .MAX_RESULT_BUFFER ;
46
- import static org .postgresql .PGProperty .PREPARE_THRESHOLD ;
47
42
48
43
import com .fasterxml .jackson .databind .JsonNode ;
49
44
import com .fasterxml .jackson .databind .node .ObjectNode ;
57
52
import io .airbyte .cdk .db .jdbc .JdbcDatabase ;
58
53
import io .airbyte .cdk .db .jdbc .JdbcUtils ;
59
54
import io .airbyte .cdk .db .jdbc .StreamingJdbcDatabase ;
55
+ import io .airbyte .cdk .db .jdbc .streaming .AdaptiveStreamingQueryConfig ;
60
56
import io .airbyte .cdk .integrations .base .AirbyteTraceMessageUtility ;
61
57
import io .airbyte .cdk .integrations .base .IntegrationRunner ;
62
58
import io .airbyte .cdk .integrations .base .Source ;
126
122
import java .util .stream .Stream ;
127
123
import javax .sql .DataSource ;
128
124
import org .apache .commons .lang3 .StringUtils ;
129
- import org .postgresql .PGProperty ;
130
125
import org .slf4j .Logger ;
131
126
import org .slf4j .LoggerFactory ;
132
127
@@ -151,14 +146,6 @@ public class PostgresSource extends AbstractJdbcSource<PostgresType> implements
151
146
public static final String SSL_MODE_DISABLE = "disable" ;
152
147
public static final String SSL_MODE_REQUIRE = "require" ;
153
148
154
- public static final Map <PGProperty , String > JDBC_CONNECTION_PARAMS = ImmutableMap .of (
155
- // Initialize parameters with prepareThreshold=0 to mitigate pgbouncer errors
156
- // https://github.com/airbytehq/airbyte/issues/24796
157
- PREPARE_THRESHOLD , "0" ,
158
- DEFAULT_ROW_FETCH_SIZE , "1" ,
159
- ADAPTIVE_FETCH , "true" ,
160
- MAX_RESULT_BUFFER , "10percent" );
161
-
162
149
private List <String > schemas ;
163
150
164
151
private Set <AirbyteStreamNameNamespacePair > publicizedTablesInCdc ;
@@ -170,7 +157,7 @@ public static Source sshWrappedSource(PostgresSource source) {
170
157
}
171
158
172
159
PostgresSource () {
173
- super (DRIVER_CLASS , PostgresStreamingQueryConfig ::new , new PostgresSourceOperations ());
160
+ super (DRIVER_CLASS , AdaptiveStreamingQueryConfig ::new , new PostgresSourceOperations ());
174
161
this .stateEmissionFrequency = INTERMEDIATE_STATE_EMISSION_FREQUENCY ;
175
162
}
176
163
@@ -189,9 +176,9 @@ public ConnectorSpecification spec() throws Exception {
189
176
@ Override
190
177
public JsonNode toDatabaseConfig (final JsonNode config ) {
191
178
final List <String > additionalParameters = new ArrayList <>();
192
- for ( var e : JDBC_CONNECTION_PARAMS . entrySet ()) {
193
- additionalParameters . add ( e . getKey (). getName () + EQUALS + e . getValue ());
194
- }
179
+ // Initialize parameters with prepareThreshold=0 to mitigate pgbouncer errors
180
+ // https://github.com/airbytehq/airbyte/issues/24796
181
+ additionalParameters . add ( "prepareThreshold=0" );
195
182
196
183
final String encodedDatabaseName = URLEncoder .encode (config .get (JdbcUtils .DATABASE_KEY ).asText (), StandardCharsets .UTF_8 );
197
184
@@ -201,7 +188,7 @@ public JsonNode toDatabaseConfig(final JsonNode config) {
201
188
encodedDatabaseName ));
202
189
203
190
if (config .get (JdbcUtils .JDBC_URL_PARAMS_KEY ) != null && !config .get (JdbcUtils .JDBC_URL_PARAMS_KEY ).asText ().isEmpty ()) {
204
- additionalParameters . add (config .get (JdbcUtils .JDBC_URL_PARAMS_KEY ).asText ());
191
+ jdbcUrl . append (config .get (JdbcUtils .JDBC_URL_PARAMS_KEY ).asText ()). append ( AMPERSAND );
205
192
}
206
193
207
194
final Map <String , String > sslParameters = parseSSLConfig (config );
@@ -219,10 +206,12 @@ public JsonNode toDatabaseConfig(final JsonNode config) {
219
206
}
220
207
221
208
if (schemas != null && !schemas .isEmpty ()) {
222
- additionalParameters .add (CURRENT_SCHEMA . getName () + EQUALS + String .join ("," , schemas ));
209
+ additionalParameters .add ("currentSchema=" + String .join ("," , schemas ));
223
210
}
224
- additionalParameters .addAll (toJDBCQueryParams (sslParameters ));
225
- jdbcUrl .append (String .join (AMPERSAND , additionalParameters ));
211
+
212
+ additionalParameters .forEach (x -> jdbcUrl .append (x ).append ("&" ));
213
+
214
+ jdbcUrl .append (toJDBCQueryParams (sslParameters ));
226
215
LOGGER .debug ("jdbc url: {}" , jdbcUrl );
227
216
final ImmutableMap .Builder <Object , Object > configBuilder = ImmutableMap .builder ()
228
217
.put (JdbcUtils .USERNAME_KEY , config .get (JdbcUtils .USERNAME_KEY ).asText ())
@@ -236,9 +225,8 @@ public JsonNode toDatabaseConfig(final JsonNode config) {
236
225
return Jsons .jsonNode (configBuilder .build ());
237
226
}
238
227
239
- public List <String > toJDBCQueryParams (final Map <String , String > sslParams ) {
240
- return Objects .isNull (sslParams )
241
- ? List .of ()
228
+ public String toJDBCQueryParams (final Map <String , String > sslParams ) {
229
+ return Objects .isNull (sslParams ) ? ""
242
230
: sslParams .entrySet ()
243
231
.stream ()
244
232
.map ((entry ) -> {
@@ -255,7 +243,7 @@ public List<String> toJDBCQueryParams(final Map<String, String> sslParams) {
255
243
}
256
244
})
257
245
.filter (s -> Objects .nonNull (s ) && !s .isEmpty ())
258
- .toList ( );
246
+ .collect ( Collectors . joining ( JdbcUtils . AMPERSAND ) );
259
247
}
260
248
261
249
@ Override
0 commit comments