From 9f654dbd8085c668fa9cf0dc86074a68ae91f405 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 17 Oct 2021 11:27:45 +0800 Subject: [PATCH] [KYUUBI #703] [FOLLOWUP] [TEST] Enhance hudi test ### _Why are the changes needed?_ Add hudi columns type test. ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1239 from simon824/huditest. Closes #703 7266ff62 [simon] [KYUUBI #703] [FOLLOWUP] [TEST] Enhance hudi test 5ea742c0 [simon] [KYUUBI #703] [FOLLOWUP] [TEST] Enhance hudi test ce7b4068 [simon] [KYUUBI #703] [FOLLOWUP] [TEST] Enhance hudi test 5582ac3e [simon] huditest Authored-by: simon Signed-off-by: Cheng Pan --- .../kyuubi/operation/BasicHudiJDBCTests.scala | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/BasicHudiJDBCTests.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/BasicHudiJDBCTests.scala index 77ef452f9..36ec2a0ba 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/BasicHudiJDBCTests.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/BasicHudiJDBCTests.scala @@ -100,4 +100,59 @@ trait BasicHudiJDBCTests extends JDBCTestUtils with HudiSuiteMixin { assert(!rs3.next()) } } + + test("get columns type") { + val dataTypes = Seq("boolean", "int", "bigint", "float", "double", "decimal(38,20)", + "decimal(10,2)", "string", "array", "array", "date", "timestamp", + "struct<`X`: bigint, `Y`: double>", "binary", "struct<`X`: string>") + val cols = dataTypes.zipWithIndex.map { case (dt, idx) => s"c$idx" -> dt } + val (colNames, _) = cols.unzip + + val reservedCols = Seq("_hoodie_commit_time", "_hoodie_commit_seqno", "_hoodie_record_key", + "_hoodie_partition_path", "_hoodie_file_name") + + val tableName = "hudi_get_col_operation" + val ddl = + s""" + |CREATE TABLE IF NOT EXISTS $catalog.$dftSchema.$tableName ( + | ${cols.map { case (cn, dt) => cn + " " + dt }.mkString(",\n")} + |) + |USING hudi""".stripMargin + + withJdbcStatement(tableName) { statement => + statement.execute(ddl) + + val metaData = statement.getConnection.getMetaData + + Seq("%", null, ".*", "c.*") foreach { columnPattern => + val rowSet = metaData.getColumns(catalog, dftSchema, tableName, columnPattern) + + import java.sql.Types._ + val expectedJavaTypes = Seq(BOOLEAN, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL, DECIMAL, + VARCHAR, ARRAY, ARRAY, DATE, TIMESTAMP, STRUCT, BINARY, STRUCT) + + var pos = 0 + while (rowSet.next()) { + assert(rowSet.getString(TABLE_CAT) === catalog) + assert(rowSet.getString(TABLE_SCHEM) === dftSchema) + assert(rowSet.getString(TABLE_NAME) === tableName) + rowSet.getString(COLUMN_NAME) match { + case name if reservedCols.contains(name) => + assert(rowSet.getInt(DATA_TYPE) === VARCHAR) + assert(rowSet.getString(TYPE_NAME) equalsIgnoreCase "STRING") + case _ => + assert(rowSet.getString(COLUMN_NAME) === colNames(pos)) + assert(rowSet.getInt(DATA_TYPE) === expectedJavaTypes(pos)) + assert(rowSet.getString(TYPE_NAME) equalsIgnoreCase dataTypes(pos)) + pos += 1 + } + } + + assert(pos === dataTypes.size, "all columns should have been verified") + } + + val rowSet = metaData.getColumns(catalog, "*", "not_exist", "not_exist") + assert(!rowSet.next()) + } + } }