-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Connector][Jdbc] Add vertica connector. (#4303)
* [Feature][Connector]Jdbc] Add vertica connector.
- Loading branch information
Showing
11 changed files
with
556 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...g/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/vertica/VerticaDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.vertica; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.JdbcRowConverter; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectTypeMapper; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class VerticaDialect implements JdbcDialect { | ||
@Override | ||
public String dialectName() { | ||
return "Vertica"; | ||
} | ||
|
||
@Override | ||
public JdbcRowConverter getRowConverter() { | ||
return new VerticaJdbcRowConverter(); | ||
} | ||
|
||
@Override | ||
public JdbcDialectTypeMapper getJdbcDialectTypeMapper() { | ||
return new VerticaTypeMapper(); | ||
} | ||
|
||
@Override | ||
public String quoteIdentifier(String identifier) { | ||
return "\"" + identifier + "\""; | ||
} | ||
|
||
@Override | ||
public Optional<String> getUpsertStatement( | ||
String database, String tableName, String[] fieldNames, String[] uniqueKeyFields) { | ||
List<String> nonUniqueKeyFields = | ||
Arrays.stream(fieldNames) | ||
.filter(fieldName -> !Arrays.asList(uniqueKeyFields).contains(fieldName)) | ||
.collect(Collectors.toList()); | ||
String valuesBinding = | ||
Arrays.stream(fieldNames) | ||
.map(fieldName -> ":" + fieldName + " " + quoteIdentifier(fieldName)) | ||
.collect(Collectors.joining(", ")); | ||
|
||
String usingClause = String.format("SELECT %s FROM DUAL", valuesBinding); | ||
String onConditions = | ||
Arrays.stream(uniqueKeyFields) | ||
.map( | ||
fieldName -> | ||
String.format( | ||
"TARGET.%s=SOURCE.%s", | ||
quoteIdentifier(fieldName), | ||
quoteIdentifier(fieldName))) | ||
.collect(Collectors.joining(" AND ")); | ||
String updateSetClause = | ||
nonUniqueKeyFields.stream() | ||
.map( | ||
fieldName -> | ||
String.format( | ||
"TARGET.%s=SOURCE.%s", | ||
quoteIdentifier(fieldName), | ||
quoteIdentifier(fieldName))) | ||
.collect(Collectors.joining(", ")); | ||
String insertFields = | ||
Arrays.stream(fieldNames) | ||
.map(this::quoteIdentifier) | ||
.collect(Collectors.joining(", ")); | ||
String insertValues = | ||
Arrays.stream(fieldNames) | ||
.map(fieldName -> "SOURCE." + quoteIdentifier(fieldName)) | ||
.collect(Collectors.joining(", ")); | ||
|
||
String upsertSQL = | ||
String.format( | ||
" MERGE INTO %s.%s TARGET" | ||
+ " USING (%s) SOURCE" | ||
+ " ON (%s) " | ||
+ " WHEN MATCHED THEN" | ||
+ " UPDATE SET %s" | ||
+ " WHEN NOT MATCHED THEN" | ||
+ " INSERT (%s) VALUES (%s)", | ||
database, | ||
tableName, | ||
usingClause, | ||
onConditions, | ||
updateSetClause, | ||
insertFields, | ||
insertValues); | ||
|
||
return Optional.of(upsertSQL); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...e/seatunnel/connectors/seatunnel/jdbc/internal/dialect/vertica/VerticaDialectFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.vertica; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectFactory; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
/** Factory for {@link VerticaDialect}. */ | ||
@AutoService(JdbcDialectFactory.class) | ||
public class VerticaDialectFactory implements JdbcDialectFactory { | ||
@Override | ||
public boolean acceptsURL(String url) { | ||
return url.startsWith("jdbc:vertica:"); | ||
} | ||
|
||
@Override | ||
public JdbcDialect create() { | ||
return new VerticaDialect(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...seatunnel/connectors/seatunnel/jdbc/internal/dialect/vertica/VerticaJdbcRowConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.vertica; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.AbstractJdbcRowConverter; | ||
|
||
public class VerticaJdbcRowConverter extends AbstractJdbcRowConverter { | ||
@Override | ||
public String converterName() { | ||
return "Vertica"; | ||
} | ||
} |
Oops, something went wrong.