1515
1616import com .google .common .collect .ImmutableList ;
1717import io .airlift .log .Logger ;
18+ import io .airlift .slice .Slice ;
19+ import io .airlift .slice .Slices ;
1820import io .trino .plugin .kudu .properties .ColumnDesign ;
1921import io .trino .plugin .kudu .properties .HashPartitionDefinition ;
2022import io .trino .plugin .kudu .properties .KuduTableProperties ;
5860
5961import java .io .IOException ;
6062import java .math .BigDecimal ;
63+ import java .nio .ByteBuffer ;
6164import java .util .ArrayList ;
6265import java .util .List ;
6366import java .util .Map ;
@@ -178,7 +181,7 @@ public List<KuduSplit> buildKuduSplits(KuduTableHandle tableHandle, DynamicFilte
178181 .boxed ().collect (toList ());
179182 for (ColumnHandle column : desiredColumns .get ()) {
180183 KuduColumnHandle k = (KuduColumnHandle ) column ;
181- int index = k .getOrdinalPosition ();
184+ int index = k .ordinalPosition ();
182185 if (index >= primaryKeyColumnCount ) {
183186 columnIndexes .add (index );
184187 }
@@ -194,7 +197,7 @@ public List<KuduSplit> buildKuduSplits(KuduTableHandle tableHandle, DynamicFilte
194197 else {
195198 if (desiredColumns .isPresent ()) {
196199 columnIndexes = desiredColumns .get ().stream ()
197- .map (handle -> ((KuduColumnHandle ) handle ).getOrdinalPosition ())
200+ .map (handle -> ((KuduColumnHandle ) handle ).ordinalPosition ())
198201 .collect (toImmutableList ());
199202 }
200203 else {
@@ -323,12 +326,12 @@ public void addColumn(SchemaTableName schemaTableName, ColumnMetadata column)
323326 String rawName = schemaEmulation .toRawName (schemaTableName );
324327 AlterTableOptions alterOptions = new AlterTableOptions ();
325328 Type type = TypeHelper .toKuduClientType (column .getType ());
326- alterOptions . addColumn (
327- new ColumnSchemaBuilder ( column . getName (), type )
328- . nullable ( true )
329- . defaultValue ( null )
330- . comment ( nullToEmpty ( column . getComment ())) // Kudu doesn't allow null comment
331- .build ());
329+ ColumnSchemaBuilder builder = new ColumnSchemaBuilder ( column . getName (), type )
330+ . nullable ( true )
331+ . defaultValue ( null )
332+ . comment ( nullToEmpty ( column . getComment ())); // Kudu doesn't allow null comment
333+ setTypeAttributes ( column , builder );
334+ alterOptions . addColumn ( builder .build ());
332335 client .alterTable (rawName , alterOptions );
333336 }
334337 catch (KuduException e ) {
@@ -384,8 +387,8 @@ private void changeRangePartition(SchemaTableName schemaTableName, RangePartitio
384387 if (definition == null ) {
385388 throw new TrinoException (QUERY_REJECTED , "Table " + schemaTableName + " has no range partition" );
386389 }
387- PartialRow lowerBound = KuduTableProperties .toRangeBoundToPartialRow (schema , definition , rangePartition .getLower ());
388- PartialRow upperBound = KuduTableProperties .toRangeBoundToPartialRow (schema , definition , rangePartition .getUpper ());
390+ PartialRow lowerBound = KuduTableProperties .toRangeBoundToPartialRow (schema , definition , rangePartition .lower ());
391+ PartialRow upperBound = KuduTableProperties .toRangeBoundToPartialRow (schema , definition , rangePartition .upper ());
389392 AlterTableOptions alterOptions = new AlterTableOptions ();
390393 switch (change ) {
391394 case ADD :
@@ -467,19 +470,19 @@ private CreateTableOptions buildCreateTableOptions(Schema schema, Map<String, Ob
467470 PartitionDesign partitionDesign = KuduTableProperties .getPartitionDesign (properties );
468471 if (partitionDesign .getHash () != null ) {
469472 for (HashPartitionDefinition partition : partitionDesign .getHash ()) {
470- options .addHashPartitions (partition .getColumns (), partition .getBuckets ());
473+ options .addHashPartitions (partition .columns (), partition .buckets ());
471474 }
472475 }
473476 if (partitionDesign .getRange () != null ) {
474477 rangePartitionDefinition = partitionDesign .getRange ();
475- options .setRangePartitionColumns (rangePartitionDefinition .getColumns ());
478+ options .setRangePartitionColumns (rangePartitionDefinition .columns ());
476479 }
477480
478481 List <RangePartition > rangePartitions = KuduTableProperties .getRangePartitions (properties );
479482 if (rangePartitionDefinition != null && !rangePartitions .isEmpty ()) {
480483 for (RangePartition rangePartition : rangePartitions ) {
481- PartialRow lower = KuduTableProperties .toRangeBoundToPartialRow (schema , rangePartitionDefinition , rangePartition .getLower ());
482- PartialRow upper = KuduTableProperties .toRangeBoundToPartialRow (schema , rangePartitionDefinition , rangePartition .getUpper ());
484+ PartialRow lower = KuduTableProperties .toRangeBoundToPartialRow (schema , rangePartitionDefinition , rangePartition .lower ());
485+ PartialRow upper = KuduTableProperties .toRangeBoundToPartialRow (schema , rangePartitionDefinition , rangePartition .upper ());
483486 options .addRangePartition (lower , upper );
484487 }
485488 }
@@ -503,7 +506,7 @@ private void addConstraintPredicates(KuduTable table, KuduScanToken.KuduScanToke
503506
504507 Schema schema = table .getSchema ();
505508 constraintSummary .getDomains ().orElseThrow ().forEach ((columnHandle , domain ) -> {
506- int position = ((KuduColumnHandle ) columnHandle ).getOrdinalPosition ();
509+ int position = ((KuduColumnHandle ) columnHandle ).ordinalPosition ();
507510 ColumnSchema columnSchema = schema .getColumnByIndex (position );
508511 verify (!domain .isNone (), "Domain is none" );
509512 if (domain .isAll ()) {
@@ -529,8 +532,8 @@ else if (domain.isSingleValue()) {
529532 KuduPredicate predicate = createInListPredicate (columnSchema , discreteValues );
530533 builder .addPredicate (predicate );
531534 }
532- else if (valueSet instanceof SortedRangeSet ) {
533- Ranges ranges = (( SortedRangeSet ) valueSet ) .getRanges ();
535+ else if (valueSet instanceof SortedRangeSet sortedRangeSet ) {
536+ Ranges ranges = sortedRangeSet .getRanges ();
534537 List <Range > rangeList = ranges .getOrderedRanges ();
535538 if (rangeList .stream ().allMatch (Range ::isSingleValue )) {
536539 io .trino .spi .type .Type type = TypeHelper .fromKuduColumn (columnSchema );
@@ -577,35 +580,39 @@ private KuduPredicate createComparisonPredicate(ColumnSchema columnSchema, KuduP
577580 {
578581 io .trino .spi .type .Type type = TypeHelper .fromKuduColumn (columnSchema );
579582 Object javaValue = TypeHelper .getJavaValue (type , value );
580- if (javaValue instanceof Long ) {
581- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( Long ) javaValue );
583+ if (javaValue instanceof Long longValue ) {
584+ return KuduPredicate .newComparisonPredicate (columnSchema , op , longValue );
582585 }
583- if (javaValue instanceof BigDecimal ) {
584- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( BigDecimal ) javaValue );
586+ if (javaValue instanceof BigDecimal bigDecimal ) {
587+ return KuduPredicate .newComparisonPredicate (columnSchema , op , bigDecimal );
585588 }
586- if (javaValue instanceof Integer ) {
587- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( Integer ) javaValue );
589+ if (javaValue instanceof Integer integerValue ) {
590+ return KuduPredicate .newComparisonPredicate (columnSchema , op , integerValue );
588591 }
589- if (javaValue instanceof Short ) {
590- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( Short ) javaValue );
592+ if (javaValue instanceof Short shortValue ) {
593+ return KuduPredicate .newComparisonPredicate (columnSchema , op , shortValue );
591594 }
592- if (javaValue instanceof Byte ) {
593- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( Byte ) javaValue );
595+ if (javaValue instanceof Byte byteValue ) {
596+ return KuduPredicate .newComparisonPredicate (columnSchema , op , byteValue );
594597 }
595- if (javaValue instanceof String ) {
596- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( String ) javaValue );
598+ if (javaValue instanceof String stringValue ) {
599+ return KuduPredicate .newComparisonPredicate (columnSchema , op , stringValue );
597600 }
598- if (javaValue instanceof Double ) {
599- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( Double ) javaValue );
601+ if (javaValue instanceof Double doubleValue ) {
602+ return KuduPredicate .newComparisonPredicate (columnSchema , op , doubleValue );
600603 }
601- if (javaValue instanceof Float ) {
602- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( Float ) javaValue );
604+ if (javaValue instanceof Float floatValue ) {
605+ return KuduPredicate .newComparisonPredicate (columnSchema , op , floatValue );
603606 }
604- if (javaValue instanceof Boolean ) {
605- return KuduPredicate .newComparisonPredicate (columnSchema , op , ( Boolean ) javaValue );
607+ if (javaValue instanceof Boolean booleanValue ) {
608+ return KuduPredicate .newComparisonPredicate (columnSchema , op , booleanValue );
606609 }
607- if (javaValue instanceof byte []) {
608- return KuduPredicate .newComparisonPredicate (columnSchema , op , (byte []) javaValue );
610+ if (javaValue instanceof byte [] byteArrayValue ) {
611+ return KuduPredicate .newComparisonPredicate (columnSchema , op , byteArrayValue );
612+ }
613+ if (javaValue instanceof ByteBuffer byteBuffer ) {
614+ Slice slice = Slices .wrappedHeapBuffer (byteBuffer );
615+ return KuduPredicate .newComparisonPredicate (columnSchema , op , slice .getBytes (0 , slice .length ()));
609616 }
610617 if (javaValue == null ) {
611618 throw new IllegalStateException ("Unexpected null java value for column " + columnSchema .getName ());
0 commit comments