This is an automated email from the ASF dual-hosted git repository.
ajantha pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/carbondata.git
The following commit(s) were added to refs/heads/master by this push:
new c8cec12 [CARBONDATA-4089] Create table with location, if the location
doesn't have scheme, the default will be local file system, which is not the
file system defined by fs.defaultFS
c8cec12 is described below
commit c8cec126694590d66144025aab0fd044ec7f6a34
Author: jack86596 <[email protected]>
AuthorDate: Tue Dec 22 22:11:40 2020 +0800
[CARBONDATA-4089] Create table with location, if the location doesn't have
scheme, the default will be local file system, which is not the file system
defined by fs.defaultFS
Why is this PR needed?
Create table with location, if the location doesn't have scheme, the
default will be local file system, which is not the file system defined by
fs.defaultFS.
What changes were proposed in this PR?
If the location doesn't have scheme, add the fs.defaultFS scheme to the
beginning of the location.
Does this PR introduce any user interface change?
No
Is any new testcase added?
Yes
This closes #4065
---
.../scala/org/apache/spark/sql/CarbonEnv.scala | 12 +++---
.../createTable/TestCreateTablePath.scala | 43 ++++++++++++++++++++++
2 files changed, 50 insertions(+), 5 deletions(-)
diff --git
a/integration/spark/src/main/scala/org/apache/spark/sql/CarbonEnv.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/CarbonEnv.scala
index cb6060d..48d8fd9 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/CarbonEnv.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/CarbonEnv.scala
@@ -19,6 +19,7 @@ package org.apache.spark.sql
import java.util.concurrent.ConcurrentHashMap
+import org.apache.hadoop.fs.Path
import org.apache.spark.internal.config.ConfigEntry
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.analysis.{NoSuchDatabaseException,
NoSuchTableException}
@@ -378,14 +379,15 @@ object CarbonEnv {
isExternal: Boolean,
isTransactionalTable: Boolean
)(sparkSession: SparkSession): String = {
- val path = location.getOrElse(
+ var tmpPath = location.getOrElse(
CarbonEnv.newTablePath(databaseNameOp, tableName)(sparkSession))
if (!isExternal && isTransactionalTable && location.isEmpty &&
- (FileFactory.getCarbonFile(path).exists() ||
EnvHelper.isLegacy(sparkSession))) {
- path + "_" + tableId
- } else {
- path
+ (FileFactory.getCarbonFile(tmpPath).exists() ||
EnvHelper.isLegacy(sparkSession))) {
+ tmpPath = tmpPath + "_" + tableId
}
+ val path = new Path(tmpPath)
+ val fs = path.getFileSystem(sparkSession.sparkContext.hadoopConfiguration)
+ fs.makeQualified(path).toString
}
def getIdentifier(
diff --git
a/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTablePath.scala
b/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTablePath.scala
new file mode 100644
index 0000000..dd3ddc0
--- /dev/null
+++
b/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTablePath.scala
@@ -0,0 +1,43 @@
+/*
+ * 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.carbondata.spark.testsuite.createTable
+
+import org.apache.spark.sql.CarbonEnv
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
+
+/**
+ * Test functionality of create table with location
+ */
+class TestCreateTablePath extends QueryTest with BeforeAndAfterAll {
+
+ test("test create table path with location") {
+ val tablePath1 = (CarbonEnv.createTablePath(Some("default"),
"table_with_location", "1",
+ Some("/tmp/table_with_location"), isExternal = false,
+ isTransactionalTable = true)(sqlContext.sparkSession))
+ assert(tablePath1.startsWith("file:/"))
+
+ sqlContext.sparkContext.hadoopConfiguration.set("fs.defaultFS",
"hdfs://localhost")
+ val tablePath2 = CarbonEnv.createTablePath(Some("default"),
"table_with_location", "1",
+ Some("/tmp/table_with_location"), isExternal = false,
+ isTransactionalTable = true)(sqlContext.sparkSession)
+ assert(tablePath2.startsWith("hdfs://localhost/"))
+ sqlContext.sparkContext.hadoopConfiguration.set("fs.defaultFS", "file:///")
+ }
+
+}