luocooong commented on a change in pull request #2384:
URL: https://github.com/apache/drill/pull/2384#discussion_r768390098
##########
File path: pom.xml
##########
@@ -140,6 +140,7 @@
<iceberg.version>0.12.1</iceberg.version>
<univocity-parsers.version>2.8.3</univocity-parsers.version>
<junit.args/>
+ <mongo.version>4.3.3</mongo.version>
Review comment:
Recommended to keep `<junit.args/>` at the end.
##########
File path:
metastore/mongo-metastore/src/main/java/org/apache/drill/metastore/mongo/MongoMetastore.java
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.metastore.mongo;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.ConnectionString;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.metastore.Metastore;
+import org.apache.drill.metastore.components.tables.Tables;
+import org.apache.drill.metastore.components.views.Views;
+import org.apache.drill.metastore.mongo.components.tables.MongoTables;
+import org.apache.drill.metastore.mongo.config.MongoConfigConstants;
+import org.apache.drill.metastore.mongo.exception.MongoMetastoreException;
+import org.bson.Document;
+
+/**
+ * Mongo Drill Metastore implementation.
+ */
+public class MongoMetastore implements Metastore {
+
+ private final MongoClient client;
+ private final String database;
+ private final String tableCollection;
+
+ public MongoMetastore(DrillConfig config) {
+ this.client = MongoClients.create(
+ new ConnectionString(config.getString(MongoConfigConstants.CONNECTION)));
+ if(config.hasPath(MongoConfigConstants.DATABASE)) {
Review comment:
Keep a space between `if` and `()`. the same below.
Please check all code blocks (and other classes).
##########
File path:
metastore/mongo-metastore/src/main/java/org/apache/drill/metastore/mongo/MongoMetastore.java
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.metastore.mongo;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.ConnectionString;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.metastore.Metastore;
+import org.apache.drill.metastore.components.tables.Tables;
+import org.apache.drill.metastore.components.views.Views;
+import org.apache.drill.metastore.mongo.components.tables.MongoTables;
+import org.apache.drill.metastore.mongo.config.MongoConfigConstants;
+import org.apache.drill.metastore.mongo.exception.MongoMetastoreException;
+import org.bson.Document;
+
+/**
+ * Mongo Drill Metastore implementation.
+ */
+public class MongoMetastore implements Metastore {
+
+ private final MongoClient client;
+ private final String database;
+ private final String tableCollection;
+
+ public MongoMetastore(DrillConfig config) {
+ this.client = MongoClients.create(
+ new ConnectionString(config.getString(MongoConfigConstants.CONNECTION)));
+ if(config.hasPath(MongoConfigConstants.DATABASE)) {
+ this.database = config.getString(MongoConfigConstants.DATABASE);
+ } else {
+ this.database = MongoConfigConstants.DEFAULT_DATABASE;
+ }
+ if(config.hasPath(MongoConfigConstants.TABLE_COLLECTION)) {
+ this.tableCollection =
config.getString(MongoConfigConstants.TABLE_COLLECTION);
+ } else {
+ this.tableCollection = MongoConfigConstants.DEFAULT_TABLE_COLLECTION;
+ }
+ if (config.hasPath(MongoConfigConstants.IS_SHARDED) &&
+ config.getBoolean(MongoConfigConstants.IS_SHARDED)) {
+ initShardedCollection();
+ }
+ }
+
+ @Override
+ public Tables tables() {
+ return new MongoTables(
+ client.getDatabase(database).getCollection(tableCollection), client);
+ }
+
+ @Override
+ public Views views() {
+ throw new UnsupportedOperationException("Views metadata support is not
implemented");
+ }
+
+ private void initShardedCollection() {
+ FindIterable<Document> dbs = this.client.getDatabase("config")
+ .getCollection("databases")
+ .find(new Document()
+ .append(MongoConfigConstants.ID, database));
+ if (!dbs.cursor().hasNext()) {
+ shardDatabase();
+ shardCollection();
+ } else {
+ Document doc = dbs.cursor().next();
+ if (!doc.getBoolean("partitioned")) {
+ shardDatabase();
+ }
+ FindIterable<Document> collections = this.client.getDatabase("config")
+ .getCollection("collections")
+ .find(new Document()
+ .append(MongoConfigConstants.ID, database+"."+tableCollection)
Review comment:
Keep a space between `+` and variable. the same below.
Please check all code blocks (and other classes).
##########
File path:
metastore/mongo-metastore/src/main/java/org/apache/drill/metastore/mongo/MongoMetastore.java
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.metastore.mongo;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.ConnectionString;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.metastore.Metastore;
+import org.apache.drill.metastore.components.tables.Tables;
+import org.apache.drill.metastore.components.views.Views;
+import org.apache.drill.metastore.mongo.components.tables.MongoTables;
+import org.apache.drill.metastore.mongo.config.MongoConfigConstants;
+import org.apache.drill.metastore.mongo.exception.MongoMetastoreException;
+import org.bson.Document;
+
+/**
+ * Mongo Drill Metastore implementation.
+ */
+public class MongoMetastore implements Metastore {
+
+ private final MongoClient client;
+ private final String database;
+ private final String tableCollection;
+
+ public MongoMetastore(DrillConfig config) {
+ this.client = MongoClients.create(
+ new ConnectionString(config.getString(MongoConfigConstants.CONNECTION)));
+ if(config.hasPath(MongoConfigConstants.DATABASE)) {
+ this.database = config.getString(MongoConfigConstants.DATABASE);
+ } else {
+ this.database = MongoConfigConstants.DEFAULT_DATABASE;
+ }
+ if(config.hasPath(MongoConfigConstants.TABLE_COLLECTION)) {
+ this.tableCollection =
config.getString(MongoConfigConstants.TABLE_COLLECTION);
+ } else {
+ this.tableCollection = MongoConfigConstants.DEFAULT_TABLE_COLLECTION;
+ }
+ if (config.hasPath(MongoConfigConstants.IS_SHARDED) &&
+ config.getBoolean(MongoConfigConstants.IS_SHARDED)) {
+ initShardedCollection();
+ }
+ }
+
+ @Override
+ public Tables tables() {
+ return new MongoTables(
+ client.getDatabase(database).getCollection(tableCollection), client);
+ }
+
+ @Override
+ public Views views() {
+ throw new UnsupportedOperationException("Views metadata support is not
implemented");
+ }
+
+ private void initShardedCollection() {
+ FindIterable<Document> dbs = this.client.getDatabase("config")
+ .getCollection("databases")
+ .find(new Document()
+ .append(MongoConfigConstants.ID, database));
+ if (!dbs.cursor().hasNext()) {
+ shardDatabase();
+ shardCollection();
+ } else {
+ Document doc = dbs.cursor().next();
+ if (!doc.getBoolean("partitioned")) {
+ shardDatabase();
+ }
+ FindIterable<Document> collections = this.client.getDatabase("config")
+ .getCollection("collections")
+ .find(new Document()
+ .append(MongoConfigConstants.ID, database+"."+tableCollection)
+ .append("distributionMode", "sharded"));
+ if (!collections.cursor().hasNext()) {
+ shardCollection();
+ } else {
+ Document shardKey = (Document) dbs.cursor().next().get("key");
+ if (shardKey.size() != 1 ||
!shardKey.containsKey(MongoConfigConstants.ID)
+ || !shardKey.containsValue("hashed")) {
+ throw new MongoMetastoreException(
+ String.format("%s.%s(with shard key %s) is not hash sharded and " +
+ "only hash sharded by %s", database, tableCollection,
+ shardKey.toString(), MongoConfigConstants.ID));
+ }
+ }
+ }
+ }
+
+ private void shardDatabase() {
Review comment:
In general, we use strict role permissions in production environment,
mongo DBA can create db with `dbOwner` role for you (custom database) at most.
If the app need access to `admin` and `config` (built-in databases), it must
need more permissions... In fact, there are two options :
1. Remove these and return the operation to the DBA/USER (use these codes
only in unit tests).
2. Document this requirement in the docs, please see also [Built-In
Roles](https://docs.mongodb.com/v4.2/reference/built-in-roles/).
##########
File path: distribution/src/main/resources/drill-metastore-override-example.conf
##########
@@ -21,8 +21,16 @@
drill.metastore: {
# For Drill Iceberg Metastore use:
org.apache.drill.metastore.iceberg.IcebergMetastore
+ # For Drill Mongo Metastore use:
org.apache.drill.metastore.mongo.MongoMetastore
implementation.class: "org.apache.drill.metastore.rdbms.RdbmsMetastore",
+ mongo: {
+ # connection: "mongodb://localhost:27017/",
+ # is_sharded: false,
+ # database: meta,
Review comment:
```suggestion
# database: "meta",
```
The same below.
##########
File path:
metastore/mongo-metastore/src/test/java/org/apache/drill/metastore/mongo/components/tables/TestTablesOperationTransformer.java
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.metastore.mongo.components.tables;
+
+import com.mongodb.client.model.Filters;
+import com.typesafe.config.ConfigValueFactory;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.metastore.MetastoreColumn;
+import org.apache.drill.metastore.components.tables.TableMetadataUnit;
+import org.apache.drill.metastore.expressions.FilterExpression;
+import org.apache.drill.metastore.metadata.MetadataType;
+import org.apache.drill.metastore.mongo.MongoMetastore;
+import org.apache.drill.metastore.mongo.config.MongoConfigConstants;
+import org.apache.drill.metastore.mongo.operate.MongoDelete;
+import org.apache.drill.metastore.mongo.operate.Overwrite;
+import org.apache.drill.metastore.mongo.transform.InputDataTransformer;
+import org.apache.drill.metastore.mongo.transform.OperationTransformer;
+import org.apache.drill.metastore.operate.Delete;
+import org.bson.Document;
+import org.bson.conversions.Bson;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTablesOperationTransformer {
+
+ private static OperationTransformer<TableMetadataUnit> transformer;
+ private static MongoMetastore metastore;
+
+ @BeforeClass
+ public static void init() {
+ DrillConfig drillConfig = new
DrillConfig(DrillConfig.create().withValue(MongoConfigConstants.CONNECTION,
+
ConfigValueFactory.fromAnyRef("mongodb://localhost:27017/?connectTimeoutMS=60000&maxPoolSize=1000&safe=true")));
+ metastore = new MongoMetastore(drillConfig);
+ transformer = new
TablesOperationTransformer(((MongoTables)metastore.tables()).context());
+ }
+
+ @Test
+ public void testToOverwriteOperation() {
+ TableMetadataUnit unit = TableMetadataUnit.builder()
+ .storagePlugin("dfs").workspace("tmp").tableName("nation")
+
.metadataType(MetadataType.TABLE.name()).metadataIdentifier("s1").build();
+ List<Overwrite> operations =
transformer.toOverwrite(Collections.singletonList(unit));
+ InputDataTransformer<TableMetadataUnit> inputDataTransformer =
+ ((MongoTables)metastore.tables()).transformer().inputData();
Review comment:
Keep a space between `()` and variable the same below.
Please check all code blocks (and other classes).
##########
File path:
metastore/mongo-metastore/src/main/java/org/apache/drill/metastore/mongo/components/tables/TablesOutputDataTransformer.java
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.metastore.mongo.components.tables;
+
+import org.apache.drill.metastore.mongo.exception.MongoMetastoreException;
+import org.apache.drill.metastore.mongo.transform.OutputDataTransformer;
+import org.apache.drill.metastore.components.tables.TableMetadataUnit;
+
+import java.lang.invoke.MethodHandle;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Metastore Tables component output data transformer that transforms
+ * {@link org.bson.Document} into {@link TableMetadataUnit}.
+ */
+public class TablesOutputDataTransformer extends
OutputDataTransformer<TableMetadataUnit> {
+
+ public TablesOutputDataTransformer(Map<String, MethodHandle> unitSetters) {
+ super(unitSetters);
+ }
+
+ @Override
+ public List<TableMetadataUnit> execute() {
+ List<TableMetadataUnit> results = new ArrayList<>();
+ for (Map<MethodHandle, Object> valueToSet : valuesToSet()) {
+ TableMetadataUnit.Builder builder = TableMetadataUnit.builder();
Review comment:
Is it possible to move this line outside the loop?
##########
File path:
metastore/mongo-metastore/src/main/resources/drill-metastore-module.conf
##########
@@ -0,0 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+drill.metastore.mongo: {
+ connection:
"mongodb://localhost:27017/?connectTimeoutMS=60000&maxPoolSize=1000&safe=true"
Review comment:
In order to be "out of the box", just keep `"mongodb://localhost:27017"`.
##########
File path:
metastore/mongo-metastore/src/main/java/org/apache/drill/metastore/mongo/MongoMetastore.java
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.metastore.mongo;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.ConnectionString;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.metastore.Metastore;
+import org.apache.drill.metastore.components.tables.Tables;
+import org.apache.drill.metastore.components.views.Views;
+import org.apache.drill.metastore.mongo.components.tables.MongoTables;
+import org.apache.drill.metastore.mongo.config.MongoConfigConstants;
+import org.apache.drill.metastore.mongo.exception.MongoMetastoreException;
+import org.bson.Document;
+
+/**
+ * Mongo Drill Metastore implementation.
+ */
+public class MongoMetastore implements Metastore {
+
+ private final MongoClient client;
+ private final String database;
+ private final String tableCollection;
+
+ public MongoMetastore(DrillConfig config) {
+ this.client = MongoClients.create(
+ new ConnectionString(config.getString(MongoConfigConstants.CONNECTION)));
+ if(config.hasPath(MongoConfigConstants.DATABASE)) {
+ this.database = config.getString(MongoConfigConstants.DATABASE);
+ } else {
+ this.database = MongoConfigConstants.DEFAULT_DATABASE;
+ }
+ if(config.hasPath(MongoConfigConstants.TABLE_COLLECTION)) {
+ this.tableCollection =
config.getString(MongoConfigConstants.TABLE_COLLECTION);
+ } else {
+ this.tableCollection = MongoConfigConstants.DEFAULT_TABLE_COLLECTION;
+ }
+ if (config.hasPath(MongoConfigConstants.IS_SHARDED) &&
+ config.getBoolean(MongoConfigConstants.IS_SHARDED)) {
+ initShardedCollection();
+ }
+ }
+
+ @Override
+ public Tables tables() {
+ return new MongoTables(
+ client.getDatabase(database).getCollection(tableCollection), client);
+ }
+
+ @Override
+ public Views views() {
+ throw new UnsupportedOperationException("Views metadata support is not
implemented");
+ }
+
+ private void initShardedCollection() {
+ FindIterable<Document> dbs = this.client.getDatabase("config")
+ .getCollection("databases")
+ .find(new Document()
+ .append(MongoConfigConstants.ID, database));
Review comment:
New line is not recommended.
##########
File path:
metastore/mongo-metastore/src/test/java/org/apache/drill/metastore/mongo/MongoBaseTest.java
##########
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.metastore.mongo;
+
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigValueFactory;
+import org.apache.drill.categories.MetastoreTest;
+import org.apache.drill.common.config.DrillConfig;
+import
org.apache.drill.metastore.components.tables.AbstractBasicTablesRequestsTest;
+import org.apache.drill.metastore.mongo.config.MongoConfigConstants;
+import org.apache.drill.shaded.guava.com.google.common.collect.Lists;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.experimental.categories.Category;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.containers.Network;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@Category(MetastoreTest.class)
+public class MongoBaseTest extends AbstractBasicTablesRequestsTest {
+ private static final Logger logger =
LoggerFactory.getLogger(MongoBaseTest.class);
+
+ private static final String MONGO_IMAGE_NAME = "mongo:4.4.5";
Review comment:
The `mongo-storage` use the 4.4.10.
##########
File path:
metastore/mongo-metastore/src/test/java/org/apache/drill/metastore/mongo/components/tables/TestMongoBasicTablesRequests.java
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.metastore.mongo.components.tables;
+
+import org.apache.drill.metastore.components.tables.MetastoreTableInfo;
+import org.apache.drill.metastore.components.tables.TableMetadataUnit;
+import org.apache.drill.metastore.metadata.MetadataType;
+import org.apache.drill.metastore.mongo.MongoBaseTest;
+import org.apache.drill.metastore.operate.Delete;
+import org.apache.drill.metastore.operate.Metadata;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class TestMongoBasicTablesRequests extends MongoBaseTest {
+
+ @Test
+ public void testMetastoreTableInfoExistingTable() {
+ MetastoreTableInfo metastoreTableInfo =
basicRequests.metastoreTableInfo(nationTableInfo);
+ assertTrue(metastoreTableInfo.isExists());
+ assertEquals(nationTableInfo, metastoreTableInfo.tableInfo());
+ assertEquals(nationTable.lastModifiedTime(),
metastoreTableInfo.lastModifiedTime());
+ assertEquals(Metadata.UNDEFINED, metastoreTableInfo.metastoreVersion());
+ }
+
+ @Test
+ public void testDelete() {
+ MetastoreTableInfo metastoreTableInfo =
basicRequests.metastoreTableInfo(nationTableInfo);
+ assertTrue(metastoreTableInfo.isExists());
+ tables.modify()
+ .delete(Delete.builder()
+ .metadataType(MetadataType.TABLE)
+ .filter(nationTableInfo.toFilter())
+ .build())
+ .execute();
+ metastoreTableInfo = basicRequests.metastoreTableInfo(nationTableInfo);
+ assertFalse(metastoreTableInfo.isExists());
+
+ List<TableMetadataUnit> res =
+ tables.read().metadataType(MetadataType.ALL).execute();
+ assertFalse(res.isEmpty());
+ tables.modify().purge();
+ res =
+ tables.read().metadataType(MetadataType.ALL).execute();
Review comment:
New line is not recommended.
##########
File path: distribution/src/main/resources/drill-metastore-override-example.conf
##########
@@ -21,8 +21,16 @@
drill.metastore: {
# For Drill Iceberg Metastore use:
org.apache.drill.metastore.iceberg.IcebergMetastore
+ # For Drill Mongo Metastore use:
org.apache.drill.metastore.mongo.MongoMetastore
implementation.class: "org.apache.drill.metastore.rdbms.RdbmsMetastore",
+ mongo: {
Review comment:
Recommended to put the configuration snippet behind the `Iceberg`.
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/record/SchemaUtil.java
##########
@@ -214,7 +214,13 @@ public static TupleMetadata fromBatchSchema(BatchSchema
batchSchema) {
currentNames.add(columnMetadata.name());
result.addAll(getColumnPaths(columnMetadata.tupleSchema(),
currentNames));
} else {
- result.add(Collections.singletonList(columnMetadata.name()));
+ if (parentNames != null) {
Review comment:
Thanks for your fix!
And then, how do we reproduce this bug? is it possible to add an unit test
for this case?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]