forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69cd4ae
commit b7fc979
Showing
6 changed files
with
286 additions
and
15 deletions.
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
85 changes: 85 additions & 0 deletions
85
.../java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/GenericDialect.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,85 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.seatunnel.api.table.catalog.TablePath; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.AbstractJdbcRowConverter; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.JdbcRowConverter; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.dialectenum.FieldIdeEnum; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
public class GenericDialect implements JdbcDialect { | ||
|
||
public String fieldIde = FieldIdeEnum.ORIGINAL.getValue(); | ||
|
||
public GenericDialect() {} | ||
|
||
public GenericDialect(String fieldIde) { | ||
this.fieldIde = fieldIde; | ||
} | ||
|
||
@Override | ||
public String dialectName() { | ||
return DatabaseIdentifier.GENERIC; | ||
} | ||
|
||
@Override | ||
public JdbcRowConverter getRowConverter() { | ||
return new AbstractJdbcRowConverter() { | ||
@Override | ||
public String converterName() { | ||
return DatabaseIdentifier.GENERIC; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public JdbcDialectTypeMapper getJdbcDialectTypeMapper() { | ||
return new GenericTypeMapper(); | ||
} | ||
|
||
@Override | ||
public String quoteIdentifier(String identifier) { | ||
return getFieldIde(identifier, fieldIde); | ||
} | ||
|
||
@Override | ||
public String quoteDatabaseIdentifier(String identifier) { | ||
return identifier; | ||
} | ||
|
||
@Override | ||
public String tableIdentifier(TablePath tablePath) { | ||
return tableIdentifier(tablePath.getDatabaseName(), tablePath.getTableName()); | ||
} | ||
|
||
@Override | ||
public Optional<String> getUpsertStatement( | ||
String database, String tableName, String[] fieldNames, String[] uniqueKeyFields) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public TablePath parse(String tablePath) { | ||
return TablePath.of(tablePath, false); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...rg/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/GenericDialectFactory.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,41 @@ | ||
/* | ||
* 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; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** Factory for {@link GenericDialect}. */ | ||
@AutoService(JdbcDialectFactory.class) | ||
public class GenericDialectFactory implements JdbcDialectFactory { | ||
@Override | ||
public boolean acceptsURL(String url) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public JdbcDialect create() { | ||
return new GenericDialect(); | ||
} | ||
|
||
@Override | ||
public JdbcDialect create(@Nonnull String compatibleMode, String fieldIde) { | ||
return new GenericDialect(fieldIde); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/GenericTypeConverter.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,112 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.seatunnel.api.table.catalog.Column; | ||
import org.apache.seatunnel.api.table.catalog.PhysicalColumn; | ||
import org.apache.seatunnel.api.table.converter.BasicTypeDefine; | ||
import org.apache.seatunnel.api.table.converter.TypeConverter; | ||
import org.apache.seatunnel.common.exception.CommonError; | ||
|
||
import com.google.auto.service.AutoService; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@AutoService(TypeConverter.class) | ||
public class GenericTypeConverter implements TypeConverter<BasicTypeDefine> { | ||
|
||
public static final GenericTypeConverter DEFAULT_INSTANCE = new GenericTypeConverter(); | ||
|
||
@Override | ||
public String identifier() { | ||
return DatabaseIdentifier.GENERIC; | ||
} | ||
|
||
/** | ||
* Convert an external system's type definition to {@link Column}. | ||
* | ||
* @param typeDefine type define | ||
* @return column | ||
*/ | ||
@Override | ||
public Column convert(BasicTypeDefine typeDefine) { | ||
PhysicalColumn.PhysicalColumnBuilder builder = | ||
PhysicalColumn.builder() | ||
.name(typeDefine.getName()) | ||
.nullable(typeDefine.isNullable()) | ||
.defaultValue(typeDefine.getDefaultValue()) | ||
.comment(typeDefine.getComment()); | ||
String dataType = typeDefine.getDataType().toUpperCase(); | ||
switch (dataType) { | ||
case "BOOLEAN": | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Convert {@link Column} to an external system's type definition. | ||
* | ||
* @param column | ||
* @return | ||
*/ | ||
@Override | ||
public BasicTypeDefine reconvert(Column column) { | ||
BasicTypeDefine.BasicTypeDefineBuilder builder = | ||
BasicTypeDefine.builder() | ||
.name(column.getName()) | ||
.nullable(column.isNullable()) | ||
.comment(column.getComment()) | ||
.defaultValue(column.getDefaultValue()); | ||
switch (column.getDataType().getSqlType()) { | ||
case BOOLEAN: | ||
break; | ||
case TINYINT: | ||
break; | ||
case SMALLINT: | ||
break; | ||
case INT: | ||
break; | ||
case BIGINT: | ||
break; | ||
case FLOAT: | ||
break; | ||
case DOUBLE: | ||
break; | ||
case DECIMAL: | ||
break; | ||
case STRING: | ||
break; | ||
case BYTES: | ||
break; | ||
case DATE: | ||
break; | ||
case TIME: | ||
break; | ||
case TIMESTAMP: | ||
break; | ||
default: | ||
throw CommonError.convertToConnectorTypeError( | ||
DatabaseIdentifier.GENERIC, | ||
column.getDataType().getSqlType().name(), | ||
column.getName()); | ||
} | ||
|
||
return null; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...va/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/GenericTypeMapper.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,39 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.seatunnel.api.table.catalog.Column; | ||
import org.apache.seatunnel.api.table.converter.BasicTypeDefine; | ||
|
||
public class GenericTypeMapper implements JdbcDialectTypeMapper { | ||
|
||
private GenericTypeConverter typeConverter; | ||
|
||
public GenericTypeMapper() { | ||
this(GenericTypeConverter.DEFAULT_INSTANCE); | ||
} | ||
|
||
public GenericTypeMapper(GenericTypeConverter typeConverter) { | ||
this.typeConverter = typeConverter; | ||
} | ||
|
||
@Override | ||
public Column mappingColumn(BasicTypeDefine typeDefine) { | ||
return typeConverter.convert(typeDefine); | ||
} | ||
} |
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