-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extended readMapping to columnMapping for jdbc connectors
- Loading branch information
1 parent
c61c2e4
commit b74d9ec
Showing
22 changed files
with
1,067 additions
and
514 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
28 changes: 28 additions & 0 deletions
28
presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/BooleanWriteFunction.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,28 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.plugin.jdbc; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
public interface BooleanWriteFunction | ||
extends WriteFunction | ||
{ | ||
default Class<?> getJavaType() | ||
{ | ||
return boolean.class; | ||
} | ||
|
||
void set(PreparedStatement statement, int index, boolean value) throws SQLException; | ||
} |
85 changes: 85 additions & 0 deletions
85
presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/ColumnMapping.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 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 com.facebook.presto.plugin.jdbc; | ||
|
||
import com.facebook.presto.common.type.Type; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class ColumnMapping | ||
{ | ||
private final Type type; | ||
private final ReadFunction readFunction; | ||
private final WriteFunction writeFunction; | ||
|
||
private ColumnMapping(Type type, ReadFunction readFunction, WriteFunction writeFunction) | ||
{ | ||
this.type = requireNonNull(type, "type is null"); | ||
this.readFunction = requireNonNull(readFunction, "readFunction is null"); | ||
this.writeFunction = requireNonNull(writeFunction, "writeFunction is null"); | ||
checkArgument( | ||
type.getJavaType() == readFunction.getJavaType(), | ||
"Presto type %s is not compatible with read function %s returning %s", | ||
type, | ||
readFunction, | ||
readFunction.getJavaType()); | ||
checkArgument( | ||
type.getJavaType() == writeFunction.getJavaType(), | ||
"Presto type %s is not compatible with write function %s accepting %s", | ||
type, | ||
writeFunction, | ||
writeFunction.getJavaType()); | ||
} | ||
|
||
public static ColumnMapping booleanMapping(Type prestoType, BooleanReadFunction readFunction, BooleanWriteFunction writeFunction) | ||
{ | ||
return new ColumnMapping(prestoType, readFunction, writeFunction); | ||
} | ||
|
||
public static ColumnMapping longMapping(Type prestoType, LongReadFunction readFunction, LongWriteFunction writeFunction) | ||
{ | ||
return new ColumnMapping(prestoType, readFunction, writeFunction); | ||
} | ||
|
||
public static ColumnMapping doubleMapping(Type prestoType, DoubleReadFunction readFunction, DoubleWriteFunction writeFunction) | ||
{ | ||
return new ColumnMapping(prestoType, readFunction, writeFunction); | ||
} | ||
|
||
public static ColumnMapping sliceMapping(Type prestoType, SliceReadFunction readFunction, SliceWriteFunction writeFunction) | ||
{ | ||
return new ColumnMapping(prestoType, readFunction, writeFunction); | ||
} | ||
|
||
public static ColumnMapping objectMapping(Type prestoType, ObjectReadFunction readFunction, ObjectWriteFunction writeFunction) | ||
{ | ||
return new ColumnMapping(prestoType, readFunction, writeFunction); | ||
} | ||
|
||
public Type getType() | ||
{ | ||
return type; | ||
} | ||
|
||
public ReadFunction getReadFunction() | ||
{ | ||
return readFunction; | ||
} | ||
|
||
public WriteFunction getWriteFunction() | ||
{ | ||
return writeFunction; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/DoubleWriteFunction.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,28 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.plugin.jdbc; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
public interface DoubleWriteFunction | ||
extends WriteFunction | ||
{ | ||
default Class<?> getJavaType() | ||
{ | ||
return double.class; | ||
} | ||
|
||
void set(PreparedStatement statement, int index, double value) throws SQLException; | ||
} |
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.