1515
1616import com .facebook .airlift .log .Logger ;
1717import com .facebook .presto .common .predicate .TupleDomain ;
18+ import com .facebook .presto .common .type .CharType ;
19+ import com .facebook .presto .common .type .DecimalType ;
1820import com .facebook .presto .common .type .Decimals ;
21+ import com .facebook .presto .common .type .Type ;
1922import com .facebook .presto .common .type .VarcharType ;
2023import com .facebook .presto .plugin .jdbc .BaseJdbcClient ;
2124import com .facebook .presto .plugin .jdbc .BaseJdbcConfig ;
3639import com .facebook .presto .spi .statistics .TableStatistics ;
3740import com .google .common .collect .Maps ;
3841import jakarta .inject .Inject ;
42+ import oracle .jdbc .OracleTypes ;
3943
4044import java .sql .Connection ;
4145import java .sql .DatabaseMetaData ;
4953import java .util .Map ;
5054import java .util .Optional ;
5155
56+ import static com .facebook .presto .common .type .BigintType .BIGINT ;
57+ import static com .facebook .presto .common .type .BooleanType .BOOLEAN ;
58+ import static com .facebook .presto .common .type .DateType .DATE ;
5259import static com .facebook .presto .common .type .DecimalType .createDecimalType ;
60+ import static com .facebook .presto .common .type .DoubleType .DOUBLE ;
61+ import static com .facebook .presto .common .type .IntegerType .INTEGER ;
62+ import static com .facebook .presto .common .type .RealType .REAL ;
63+ import static com .facebook .presto .common .type .TimestampType .TIMESTAMP ;
5364import static com .facebook .presto .common .type .VarcharType .createUnboundedVarcharType ;
5465import static com .facebook .presto .common .type .VarcharType .createVarcharType ;
66+ import static com .facebook .presto .common .type .Varchars .isVarcharType ;
5567import static com .facebook .presto .plugin .jdbc .JdbcErrorCode .JDBC_ERROR ;
5668import static com .facebook .presto .plugin .jdbc .mapping .StandardColumnMappings .bigintReadMapping ;
5769import static com .facebook .presto .plugin .jdbc .mapping .StandardColumnMappings .decimalReadMapping ;
5870import static com .facebook .presto .plugin .jdbc .mapping .StandardColumnMappings .doubleReadMapping ;
5971import static com .facebook .presto .plugin .jdbc .mapping .StandardColumnMappings .realReadMapping ;
6072import static com .facebook .presto .plugin .jdbc .mapping .StandardColumnMappings .smallintReadMapping ;
73+ import static com .facebook .presto .plugin .jdbc .mapping .StandardColumnMappings .timestampReadMapping ;
6174import static com .facebook .presto .plugin .jdbc .mapping .StandardColumnMappings .varbinaryReadMapping ;
6275import static com .facebook .presto .plugin .jdbc .mapping .StandardColumnMappings .varcharReadMapping ;
6376import static com .facebook .presto .spi .StandardErrorCode .NOT_SUPPORTED ;
@@ -261,6 +274,7 @@ public Optional<ReadMapping> toPrestoType(ConnectorSession session, JdbcTypeHand
261274 return Optional .of (smallintReadMapping ());
262275 case Types .FLOAT :
263276 case Types .DOUBLE :
277+ case OracleTypes .BINARY_DOUBLE :
264278 return Optional .of (doubleReadMapping ());
265279 case Types .REAL :
266280 return Optional .of (realReadMapping ());
@@ -283,10 +297,56 @@ public Optional<ReadMapping> toPrestoType(ConnectorSession session, JdbcTypeHand
283297 return Optional .of (varcharReadMapping (createVarcharType (columnSize )));
284298 case Types .VARCHAR :
285299 return Optional .of (varcharReadMapping (createVarcharType (columnSize )));
300+ case Types .DATE :
301+ case Types .TIMESTAMP :
302+ return Optional .of (timestampReadMapping ());
286303 }
287304 return super .toPrestoType (session , typeHandle );
288305 }
289306
307+ @ Override
308+ protected String toSqlType (Type type )
309+ {
310+ if (isVarcharType (type )) {
311+ VarcharType varcharType = (VarcharType ) type ;
312+ if (varcharType .isUnbounded ()) {
313+ return "VARCHAR2(4000)" ; // Oracle max before CLOB
314+ }
315+ return format ("VARCHAR2(%s)" , varcharType .getLengthSafe ());
316+ }
317+ if (type instanceof CharType ) {
318+ return format ("CHAR(%s)" , ((CharType ) type ).getLength ());
319+ }
320+ if (type instanceof DecimalType ) {
321+ return format ("NUMBER(%s, %s)" ,
322+ ((DecimalType ) type ).getPrecision (),
323+ ((DecimalType ) type ).getScale ());
324+ }
325+
326+ if (BIGINT .equals (type )) {
327+ return "NUMBER(19)" ;
328+ }
329+ if (INTEGER .equals (type )) {
330+ return "NUMBER(10)" ;
331+ }
332+ if (DOUBLE .equals (type )) {
333+ return "BINARY_DOUBLE" ;
334+ }
335+ if (REAL .equals (type )) {
336+ return "BINARY_FLOAT" ;
337+ }
338+ if (BOOLEAN .equals (type )) {
339+ return "NUMBER(1)" ;
340+ }
341+ if (DATE .equals (type )) {
342+ return "DATE" ;
343+ }
344+ if (TIMESTAMP .equals (type )) {
345+ return "TIMESTAMP" ;
346+ }
347+ return super .toSqlType (type );
348+ }
349+
290350 @ Override
291351 public String normalizeIdentifier (ConnectorSession session , String identifier )
292352 {
0 commit comments