Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MERGE for Mongo connector #23770

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ statements, the connector supports the following features:

- {doc}`/sql/insert`
- {doc}`/sql/delete`
- {doc}`/sql/update`
- {doc}`/sql/merge`
- {doc}`/sql/create-table`
- {doc}`/sql/create-table-as`
- {doc}`/sql/drop-table`
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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 io.trino.plugin.mongodb;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.connector.ConnectorMergeTableHandle;
import io.trino.spi.connector.ConnectorTableHandle;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.predicate.TupleDomain;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

public record MongoMergeTableHandle(
RemoteTableName remoteTableName,
List<MongoColumnHandle> columns,
Map<Integer, Collection<ColumnHandle>> updateCaseColumns,
MongoColumnHandle mergeRowIdColumn,
Optional<String> filter,
TupleDomain<ColumnHandle> constraint,
Optional<MongoOutputTableHandle> deleteOutputTableHandle,
Optional<MongoOutputTableHandle> updateOutputTableHandle,
Optional<String> temporaryTableName,
Optional<String> pageSinkIdColumnName)
implements ConnectorMergeTableHandle
{
public MongoMergeTableHandle
{
requireNonNull(remoteTableName, "remoteTableName is null");
columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null"));
updateCaseColumns = ImmutableMap.copyOf(requireNonNull(updateCaseColumns, "updateCaseColumns is null"));
requireNonNull(filter, "filter is null");
requireNonNull(mergeRowIdColumn, "mergeRowIdColumn is null");
requireNonNull(constraint, "constraint is null");
requireNonNull(deleteOutputTableHandle, "deleteOutputTableHandle is null");
requireNonNull(updateOutputTableHandle, "updateOutputTableHandle is null");
requireNonNull(temporaryTableName, "temporaryTableName is null");
requireNonNull(pageSinkIdColumnName, "pageSinkIdColumnName is null");
checkArgument(temporaryTableName.isPresent() == pageSinkIdColumnName.isPresent(),
"temporaryTableName.isPresent is not equal to pageSinkIdColumnName.isPresent");
}

@JsonIgnore
public Optional<RemoteTableName> getTemporaryRemoteTableName()
{
return temporaryTableName.map(tableName -> new RemoteTableName(remoteTableName.databaseName(), tableName));
}

@Override
public ConnectorTableHandle getTableHandle()
{
return new MongoTableHandle(
new SchemaTableName(remoteTableName.databaseName(), remoteTableName.collectionName()),
remoteTableName,
filter,
constraint,
ImmutableSet.of(),
OptionalInt.empty());
}
}
Loading
Loading