forked from DataLinkDC/dinky
-
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.
refactor: metadata, a little adjustitive on code (DataLinkDC#2055)
* refactor: test * refactor: * refactor: * Spotless Apply * fix: test Signed-off-by: licho <lecho.sun@gmail.com> * fix: test Signed-off-by: licho <lecho.sun@gmail.com> * Spotless Apply * refactor: add AbstractTypeConvert * Spotless Apply * chore: format * refactor: starRoocksTypeConvert Signed-off-by: Licho <lecho.sun@gmail.com> * Spotless Apply * refactor: SqlServerTypeConvert * Spotless Apply * refactor: Signed-off-by: Licho <lecho.sun@gmail.com> * Spotless Apply * refactor: revert application.yml Signed-off-by: Licho <lecho.sun@gmail.com> * refactor: add register * Spotless Apply * refactor: remove unused * refactor: all typeconvert * Spotless Apply * fix: HiveTypeConvert * fix: ClickHouseTypeConvert * Spotless Apply --------- Signed-off-by: licho <lecho.sun@gmail.com> Signed-off-by: Licho <lecho.sun@gmail.com> Co-authored-by: leechor <leechor@users.noreply.github.com>
- Loading branch information
Showing
19 changed files
with
650 additions
and
792 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
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
85 changes: 85 additions & 0 deletions
85
...ata/dinky-metadata-base/src/main/java/org/dinky/metadata/convert/AbstractTypeConvert.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.dinky.metadata.convert; | ||
|
||
import org.dinky.assertion.Asserts; | ||
import org.dinky.data.enums.ColumnType; | ||
import org.dinky.data.model.Column; | ||
import org.dinky.metadata.driver.DriverConfig; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
|
||
public class AbstractTypeConvert implements ITypeConvert { | ||
protected Map<String, BiFunction<Column, DriverConfig, Optional<ColumnType>>> convertMap = | ||
new LinkedHashMap<>(); | ||
|
||
@Override | ||
public String convertToDB(ColumnType columnType) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ColumnType convert(Column column) { | ||
return convert(column, null); | ||
} | ||
|
||
@Override | ||
public ColumnType convert(Column column, DriverConfig driverConfig) { | ||
if (Asserts.isNull(column)) { | ||
return ColumnType.STRING; | ||
} | ||
for (Map.Entry<String, BiFunction<Column, DriverConfig, Optional<ColumnType>>> entry : | ||
convertMap.entrySet()) { | ||
if (column.getType().contains(entry.getKey())) { | ||
Optional<ColumnType> columnType = entry.getValue().apply(column, driverConfig); | ||
if (columnType.isPresent()) { | ||
return columnType.get(); | ||
} | ||
} | ||
} | ||
|
||
return ColumnType.STRING; | ||
} | ||
|
||
protected void register(String type, ColumnType columnType) { | ||
this.convertMap.put(type, (c, d) -> getColumnType(c, columnType, columnType)); | ||
} | ||
|
||
protected void register(String type, ColumnType notNullType, ColumnType nullType) { | ||
this.convertMap.put(type, (c, d) -> getColumnType(c, notNullType, nullType)); | ||
} | ||
|
||
protected void register( | ||
String type, BiFunction<Column, DriverConfig, Optional<ColumnType>> func) { | ||
this.convertMap.put(type, func); | ||
} | ||
|
||
private static Optional<ColumnType> getColumnType( | ||
Column column, ColumnType notNullType, ColumnType nullType) { | ||
boolean isNullable = !column.isKeyFlag() && column.isNullable(); | ||
if (isNullable) { | ||
return Optional.of(nullType); | ||
} | ||
return Optional.of(notNullType); | ||
} | ||
} |
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
Oops, something went wrong.