3232import io .trino .spi .TrinoException ;
3333import io .trino .spi .connector .*;
3434import io .trino .spi .expression .ConnectorExpression ;
35-
36- import static com .google .common .base .Preconditions .checkArgument ;
37- import static com .google .common .base .Verify .verify ;
38- import static io .trino .plugin .jdbc .StandardColumnMappings .*;
39- import static io .trino .spi .StandardErrorCode .NOT_SUPPORTED ;
40-
4135import io .trino .spi .statistics .TableStatistics ;
4236import io .trino .spi .type .*;
4337
44- import javax .swing .text .html .Option ;
4538import java .sql .*;
4639import java .util .*;
4740import java .util .function .BiFunction ;
4841import java .util .stream .Stream ;
4942
43+ import static com .google .common .base .Preconditions .checkArgument ;
44+ import static com .google .common .base .Verify .verify ;
45+ import static com .google .common .collect .Iterables .getOnlyElement ;
5046import static io .trino .plugin .jdbc .JdbcErrorCode .JDBC_ERROR ;
5147import static io .trino .plugin .jdbc .PredicatePushdownController .FULL_PUSHDOWN ;
52-
48+ import static io .trino .plugin .jdbc .StandardColumnMappings .*;
49+ import static io .trino .spi .StandardErrorCode .NOT_SUPPORTED ;
5350import static io .trino .spi .type .BigintType .BIGINT ;
5451import static io .trino .spi .type .BooleanType .BOOLEAN ;
5552import static io .trino .spi .type .CharType .createCharType ;
56- import static io .trino .spi .type .DateTimeEncoding .packDateTimeWithZone ;
5753import static io .trino .spi .type .DateType .DATE ;
5854import static io .trino .spi .type .DecimalType .createDecimalType ;
5955import static io .trino .spi .type .DoubleType .DOUBLE ;
6359import static io .trino .spi .type .TimeType .createTimeType ;
6460import static io .trino .spi .type .TimestampType .createTimestampType ;
6561import static io .trino .spi .type .Timestamps .PICOSECONDS_PER_DAY ;
66- import static io .trino .spi .type .Timestamps .round ;
6762import static io .trino .spi .type .TinyintType .TINYINT ;
6863import static io .trino .spi .type .VarbinaryType .VARBINARY ;
6964import static io .trino .spi .type .VarcharType .createUnboundedVarcharType ;
7065import static io .trino .spi .type .VarcharType .createVarcharType ;
71-
7266import static java .lang .Math .max ;
7367import static java .lang .String .format ;
7468import static java .lang .String .join ;
7569import static java .math .RoundingMode .UNNECESSARY ;
7670import static java .util .stream .Collectors .joining ;
77- import static com .google .common .collect .Iterables .getOnlyElement ;
7871
7972public class IRISClient
8073 extends BaseJdbcClient {
@@ -114,7 +107,7 @@ public IRISClient(
114107 .map ("$like(value: varchar, pattern: varchar): boolean" ).to ("value LIKE pattern" )
115108 .map ("$like(value: varchar, pattern: varchar, escape: varchar(1)): boolean" ).to ("value LIKE pattern ESCAPE escape" )
116109 .map ("$not($is_null(value))" ).to ("value IS NOT NULL" )
117- .map ("$not(value: boolean)" ).to ("NOT value" )
110+ .map ("$not(value: boolean)" ).to ("value = 0 " )
118111 .map ("$is_null(value)" ).to ("value IS NULL" )
119112 .map ("$nullif(first, second)" ).to ("NULLIF(first, second)" )
120113 .build ();
@@ -130,15 +123,6 @@ public IRISClient(
130123 .add (new ImplementSum (IRISClient ::toTypeHandle ))
131124 .add (new ImplementAvgFloatingPoint ())
132125 .add (new ImplementAvgDecimal ())
133- // .add(new ImplementStddevSamp())
134- // .add(new ImplementStddevPop())
135- // .add(new ImplementVarianceSamp())
136- // .add(new ImplementVariancePop())
137- // .add(new ImplementCovarianceSamp())
138- // .add(new ImplementCovariancePop())
139- // .add(new ImplementCorr())
140- // .add(new ImplementRegrIntercept())
141- // .add(new ImplementRegrSlope())
142126 .build ());
143127 }
144128
@@ -149,7 +133,6 @@ public boolean schemaExists(ConnectorSession session, String schema) {
149133 }
150134
151135
152-
153136 @ Override
154137 protected void createSchema (ConnectorSession session , Connection connection , String remoteSchemaName ) throws SQLException {
155138 assert true ;
@@ -189,25 +172,66 @@ protected List<String> createTableSqls(RemoteTableName remoteTableName, List<Str
189172 return createTableSqlsBuilder .build ();
190173 }
191174
175+ @ Override
176+ protected String getColumnDefinitionSql (ConnectorSession session , ColumnMetadata column , String columnName ) {
177+ StringBuilder sb = new StringBuilder ()
178+ .append (quoted (columnName ))
179+ .append (" " )
180+ .append (toWriteMapping (session , column .getType ()).getDataType ());
181+ if (!column .isNullable ()) {
182+ sb .append (" NOT NULL" );
183+ }
184+ if (column .getComment () != null ) {
185+ sb .append (" %Description " + varcharLiteral (column .getComment ()));
186+ }
187+ return sb .toString ();
188+ }
189+
190+ @ Override
191+ protected void renameTable (ConnectorSession session , Connection connection , String catalogName , String remoteSchemaName , String remoteTableName , String newRemoteSchemaName , String newRemoteTableName )
192+ throws SQLException
193+ {
194+ if (!remoteSchemaName .equals (newRemoteSchemaName )) {
195+ throw new TrinoException (NOT_SUPPORTED , "This connector does not support renaming tables across schemas" );
196+ }
197+ execute (session , connection , format (
198+ "ALTER TABLE %s RENAME %s" ,
199+ quoted (catalogName , remoteSchemaName , remoteTableName ),
200+ quoted (null , null , newRemoteTableName )));
201+ }
202+
192203 @ Override
193204 public Collection <String > listSchemas (Connection connection ) {
194205 ImmutableSet .Builder <String > schemaNames = ImmutableSet .builder ();
195- schemaNames .addAll (super .listSchemas (connection ).stream ().filter (
196- schema ->
197- !schema .startsWith ("%" )
198- && !schema .startsWith ("ens." )
199- && !schema .startsWith ("enslib_" )
200- && !schema .startsWith ("hsfhir_" )
201- && !schema .startsWith ("hs_" )
202- ).toList ());
206+ schemaNames .addAll (super .listSchemas (connection ));
207+
203208 if (schemaTableNameOverrideExist != null ) {
204209 schemaNames .add (schemaTableNameOverrideExist );
205210 }
206- // schemaNames.add("sqluser");
207- // schemaNames.add("tpch");
211+ try {
212+ schemaNames .add (connection .getSchema ().toLowerCase ());
213+ } catch (SQLException e ) {
214+
215+ }
208216 return schemaNames .build ();
209217 }
210218
219+ protected boolean filterSchema (String schemaName ) {
220+ schemaName = schemaName .toLowerCase ();
221+ return !schemaName .startsWith ("%" )
222+ && !schemaName .equalsIgnoreCase ("information_schema" )
223+ && !schemaName .equalsIgnoreCase ("ens" )
224+ && !schemaName .equalsIgnoreCase ("ensportal" )
225+ && !schemaName .startsWith ("ens_" )
226+ && !schemaName .startsWith ("ensportal_" )
227+ && !schemaName .startsWith ("enslib_" )
228+ && !schemaName .startsWith ("hs_" )
229+ && !schemaName .startsWith ("hsfhir_" )
230+ && !schemaName .startsWith ("hsmod_" )
231+ && !schemaName .startsWith ("schemamap_" )
232+ ;
233+ }
234+
211235 @ Override
212236 public void renameSchema (ConnectorSession session , String schemaName , String newSchemaName ) {
213237 throw new TrinoException (NOT_SUPPORTED , "This connector does not support renaming schemas" );
@@ -341,6 +365,10 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
341365 return WriteMapping .objectMapping (dataType , longDecimalWriteFunction (decimalType ));
342366 }
343367
368+ if (type instanceof CharType ) {
369+ return WriteMapping .sliceMapping ("char(" + ((CharType ) type ).getLength () + ")" , charWriteFunction ());
370+ }
371+
344372 if (type instanceof VarbinaryType ) {
345373 return WriteMapping .sliceMapping ("varbinary(max)" , varbinaryWriteFunction ());
346374 }
@@ -371,8 +399,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
371399 throw new TrinoException (NOT_SUPPORTED , "Unsupported column type: " + type .getDisplayName ());
372400 }
373401
374- private static LongWriteFunction irisTimeWriteFunction (int precision )
375- {
402+ private static LongWriteFunction irisTimeWriteFunction (int precision ) {
376403 checkArgument (precision <= 12 , "Unsupported precision: %s" , precision );
377404
378405 return LongWriteFunction .of (Types .TIME , (statement , index , picosOfDay ) -> {
0 commit comments