-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sql federation column type converter spi
- Loading branch information
Showing
11 changed files
with
320 additions
and
30 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...in/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationColumnTypeConverter.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,44 @@ | ||
/* | ||
* 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.shardingsphere.sqlfederation.spi; | ||
|
||
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* SQL federation column type convert. | ||
*/ | ||
public interface SQLFederationColumnTypeConverter extends DatabaseTypedSPI { | ||
|
||
/** | ||
* Transforming the column results of a federated query. | ||
* | ||
* @param columnValue column value | ||
* @return convert column value result | ||
*/ | ||
Optional<Object> convertColumnValue(Object columnValue); | ||
|
||
/** | ||
* Converting the column types of a federated query. | ||
* | ||
* @param columnType column type | ||
* @return convert column type result | ||
*/ | ||
Optional<Integer> convertColumnType(Integer columnType); | ||
} |
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
50 changes: 50 additions & 0 deletions
50
...org/apache/shardingsphere/sqlfederation/resultset/converter/MySQLColumnTypeConverter.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,50 @@ | ||
/* | ||
* 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.shardingsphere.sqlfederation.resultset.converter; | ||
|
||
import org.apache.calcite.sql.type.SqlTypeName; | ||
import org.apache.shardingsphere.sqlfederation.spi.SQLFederationColumnTypeConverter; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* MySQL column type converter. | ||
*/ | ||
public final class MySQLColumnTypeConverter implements SQLFederationColumnTypeConverter { | ||
|
||
@Override | ||
public Optional<Object> convertColumnValue(final Object columnValue) { | ||
if (columnValue instanceof Boolean) { | ||
return Optional.of((Boolean) columnValue ? 1 : 0); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<Integer> convertColumnType(final Integer columnType) { | ||
if (SqlTypeName.BOOLEAN.getJdbcOrdinal() == columnType) { | ||
return Optional.of(SqlTypeName.BIGINT.getJdbcOrdinal()); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public String getDatabaseType() { | ||
return "MySQL"; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...apache/shardingsphere/sqlfederation/resultset/converter/OpenGaussColumnTypeConverter.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,43 @@ | ||
/* | ||
* 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.shardingsphere.sqlfederation.resultset.converter; | ||
|
||
import org.apache.shardingsphere.sqlfederation.spi.SQLFederationColumnTypeConverter; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* OpenGauss column type converter. | ||
*/ | ||
public final class OpenGaussColumnTypeConverter implements SQLFederationColumnTypeConverter { | ||
|
||
@Override | ||
public Optional<Object> convertColumnValue(final Object columnValue) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<Integer> convertColumnType(final Integer columnType) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public String getDatabaseType() { | ||
return "openGauss"; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...rg/apache/shardingsphere/sqlfederation/resultset/converter/OracleColumnTypeConverter.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,43 @@ | ||
/* | ||
* 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.shardingsphere.sqlfederation.resultset.converter; | ||
|
||
import org.apache.shardingsphere.sqlfederation.spi.SQLFederationColumnTypeConverter; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Oracle column type converter. | ||
*/ | ||
public final class OracleColumnTypeConverter implements SQLFederationColumnTypeConverter { | ||
|
||
@Override | ||
public Optional<Object> convertColumnValue(final Object columnValue) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<Integer> convertColumnType(final Integer columnType) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public String getDatabaseType() { | ||
return "Oracle"; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...pache/shardingsphere/sqlfederation/resultset/converter/PostgreSQLColumnTypeConverter.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,43 @@ | ||
/* | ||
* 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.shardingsphere.sqlfederation.resultset.converter; | ||
|
||
import org.apache.shardingsphere.sqlfederation.spi.SQLFederationColumnTypeConverter; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* PostgreSQL column type converter. | ||
*/ | ||
public final class PostgreSQLColumnTypeConverter implements SQLFederationColumnTypeConverter { | ||
|
||
@Override | ||
public Optional<Object> convertColumnValue(final Object columnValue) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<Integer> convertColumnType(final Integer columnType) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public String getDatabaseType() { | ||
return "PostgreSQL"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...INF/services/org.apache.shardingsphere.sqlfederation.spi.SQLFederationColumnTypeConverter
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,21 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
org.apache.shardingsphere.sqlfederation.resultset.converter.MySQLColumnTypeConverter | ||
org.apache.shardingsphere.sqlfederation.resultset.converter.OracleColumnTypeConverter | ||
org.apache.shardingsphere.sqlfederation.resultset.converter.OpenGaussColumnTypeConverter | ||
org.apache.shardingsphere.sqlfederation.resultset.converter.PostgreSQLColumnTypeConverter |
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.