Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class FindDataSourceTable(sparkSession: SparkSession) extends Rule[LogicalPlan]
// TODO: improve `InMemoryCatalog` and remove this limitation.
catalogTable = if (withHiveSupport) Some(table) else None)

LogicalRelation(dataSource.resolveRelation(), catalogTable = Some(table))
LogicalRelation(dataSource.resolveRelation(checkFilesExist = false),
catalogTable = Some(table))
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1431,4 +1431,30 @@ class HiveDDLSuite
}
}
}

test("insert data to a table which has altered the table location " +
"to an not exist location should success") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case names are not accurate after you add new test cases. Actually, could you split the test cases?

withTable("t") {
withTempDir { dir =>
spark.sql(
s"""create table t(a string, b int)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General style suggestions. Please use upper case for SQL keywords. For example, in this SQL statement can be improved to

CREATE TABLE t(a STRING, b INT)
USING parquet
OPTIONS(path "xyz")

|using parquet
|options(path "${dir.getAbsolutePath}")
""".stripMargin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general comment about the style. We prefer to the following indentation styles.

        sql(
          """
            |SELECT '1' AS part, key, value FROM VALUES
            |(1, "one"), (2, "two"), (3, null) AS data(key, value)
          """.stripMargin)

var table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another general comment. Please avoid using var, if possible.

assert(table.location == dir.getAbsolutePath)

var newDir = dir.getAbsolutePath.stripSuffix("/") + "/x"
spark.sql(s"alter table t set location '$newDir'")

table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
assert(table.location == newDir)
assert(!new File(newDir).exists())
checkAnswer(spark.table("t"), Nil)

spark.sql("insert into table t select 'c', 1")
checkAnswer(spark.table("t"), Row("c", 1) :: Nil)
}
}
}
}