|
15 | 15 |
|
16 | 16 | import com.google.common.collect.ImmutableList;
|
17 | 17 | import com.google.common.collect.ImmutableMap;
|
| 18 | +import com.google.common.collect.ImmutableSet; |
18 | 19 | import com.google.common.collect.Streams;
|
19 | 20 | import com.google.common.io.Closer;
|
20 | 21 | import com.mongodb.client.MongoCollection;
|
|
23 | 24 | import io.trino.plugin.mongodb.MongoIndex.MongodbIndexKey;
|
24 | 25 | import io.trino.plugin.mongodb.ptf.Query.QueryFunctionHandle;
|
25 | 26 | import io.trino.spi.TrinoException;
|
| 27 | +import io.trino.spi.connector.Assignment; |
26 | 28 | import io.trino.spi.connector.ColumnHandle;
|
27 | 29 | import io.trino.spi.connector.ColumnMetadata;
|
28 | 30 | import io.trino.spi.connector.ConnectorInsertTableHandle;
|
|
39 | 41 | import io.trino.spi.connector.LimitApplicationResult;
|
40 | 42 | import io.trino.spi.connector.LocalProperty;
|
41 | 43 | import io.trino.spi.connector.NotFoundException;
|
| 44 | +import io.trino.spi.connector.ProjectionApplicationResult; |
42 | 45 | import io.trino.spi.connector.RetryMode;
|
43 | 46 | import io.trino.spi.connector.SchemaTableName;
|
44 | 47 | import io.trino.spi.connector.SchemaTablePrefix;
|
45 | 48 | import io.trino.spi.connector.SortingProperty;
|
46 | 49 | import io.trino.spi.connector.TableFunctionApplicationResult;
|
47 | 50 | import io.trino.spi.connector.TableNotFoundException;
|
| 51 | +import io.trino.spi.expression.ConnectorExpression; |
48 | 52 | import io.trino.spi.predicate.Domain;
|
49 | 53 | import io.trino.spi.predicate.TupleDomain;
|
50 | 54 | import io.trino.spi.ptf.ConnectorTableFunctionHandle;
|
@@ -552,7 +556,7 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
|
552 | 556 | }
|
553 | 557 |
|
554 | 558 | return Optional.of(new LimitApplicationResult<>(
|
555 |
| - new MongoTableHandle(handle.getSchemaTableName(), handle.getRemoteTableName(), handle.getFilter(), handle.getConstraint(), OptionalInt.of(toIntExact(limit))), |
| 559 | + new MongoTableHandle(handle.getSchemaTableName(), handle.getRemoteTableName(), handle.getFilter(), handle.getConstraint(), handle.getProjectedColumns(), OptionalInt.of(toIntExact(limit))), |
556 | 560 | true,
|
557 | 561 | false));
|
558 | 562 | }
|
@@ -599,11 +603,41 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C
|
599 | 603 | handle.getRemoteTableName(),
|
600 | 604 | handle.getFilter(),
|
601 | 605 | newDomain,
|
| 606 | + handle.getProjectedColumns(), |
602 | 607 | handle.getLimit());
|
603 | 608 |
|
604 | 609 | return Optional.of(new ConstraintApplicationResult<>(handle, remainingFilter, false));
|
605 | 610 | }
|
606 | 611 |
|
| 612 | + @Override |
| 613 | + public Optional<ProjectionApplicationResult<ConnectorTableHandle>> applyProjection( |
| 614 | + ConnectorSession session, |
| 615 | + ConnectorTableHandle handle, |
| 616 | + List<ConnectorExpression> projections, |
| 617 | + Map<String, ColumnHandle> assignments) |
| 618 | + { |
| 619 | + MongoTableHandle mongoTableHandle = (MongoTableHandle) handle; |
| 620 | + |
| 621 | + Set<ColumnHandle> newColumns = ImmutableSet.copyOf(assignments.values()); |
| 622 | + |
| 623 | + if (newColumns.equals(mongoTableHandle.getProjectedColumns())) { |
| 624 | + return Optional.empty(); |
| 625 | + } |
| 626 | + |
| 627 | + // TODO: support dereference pushdown |
| 628 | + ImmutableSet.Builder<MongoColumnHandle> projectedColumns = ImmutableSet.builder(); |
| 629 | + ImmutableList.Builder<Assignment> assignmentList = ImmutableList.builder(); |
| 630 | + assignments.forEach((name, column) -> { |
| 631 | + MongoColumnHandle columnHandle = (MongoColumnHandle) column; |
| 632 | + assignmentList.add(new Assignment(name, column, columnHandle.getType())); |
| 633 | + projectedColumns.add(columnHandle); |
| 634 | + }); |
| 635 | + |
| 636 | + mongoTableHandle = mongoTableHandle.withProjectedColumns(projectedColumns.build()); |
| 637 | + |
| 638 | + return Optional.of(new ProjectionApplicationResult<>(mongoTableHandle, projections, assignmentList.build(), false)); |
| 639 | + } |
| 640 | + |
607 | 641 | @Override
|
608 | 642 | public Optional<TableFunctionApplicationResult<ConnectorTableHandle>> applyTableFunction(ConnectorSession session, ConnectorTableFunctionHandle handle)
|
609 | 643 | {
|
|
0 commit comments