Skip to content

table name could not be available for Kotlin dataframe JDBC #1220

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

Open
linux-china opened this issue May 27, 2025 · 3 comments
Open

table name could not be available for Kotlin dataframe JDBC #1220

linux-china opened this issue May 27, 2025 · 3 comments

Comments

@linux-china
Copy link

From

private fun getTableColumnsMetadata(rs: ResultSet): MutableList<TableColumnMetadata> {
    val metaData: ResultSetMetaData = rs.metaData
    val numberOfColumns: Int = metaData.columnCount
    val tableColumns = mutableListOf<TableColumnMetadata>()
    val columnNameCounter = mutableMapOf<String, Int>()
    val databaseMetaData: DatabaseMetaData = rs.statement.connection.metaData
    val catalog: String? = rs.statement.connection.catalog.takeUnless { it.isNullOrBlank() }
    val schema: String? = rs.statement.connection.schema.takeUnless { it.isNullOrBlank() }

    for (i in 1 until numberOfColumns + 1) {
        val tableName = metaData.getTableName(i)

val tableName = metaData.getTableName(i) could be not available for some DB vendors, such as Hive JDBC with throw new SQLFeatureNotSupportedException("Method not supported");

It is possible to make table name empty if exception thrown.

val tableName = try {
            metaData.getTableName(i)
        }   catch (e: Exception) {
            ""
        }
@zaleslaw
Copy link
Collaborator

Thanks for sharing, I suppose it’s possible, but I need some additional info:

  • are you connecting via our functional or using a custom DB class, overriding our classes?
  • what kind of vendors do you use (probably I will have a chance to test it properly)

@linux-china
Copy link
Author

@zaleslaw yes, I create a custom DB class:

object HiveDB : DbType("hive2") {
    override val driverClassName: String
        get() = "org.apache.hive.jdbc.HiveDriver"

DB vendor is Apache Hive, and code link is. https://github.com/apache/hive/blob/2d1405e7feed176aeed337581292b8438cf13326/jdbc/src/java/org/apache/hive/jdbc/HiveResultSetMetaData.java#L101


  public String getCatalogName(int column) throws SQLException {
    throw new SQLFeatureNotSupportedException("Method not supported");
  }


 public String getSchemaName(int column) throws SQLException {
    throw new SQLFeatureNotSupportedException("Method not supported");
  }

  public String getTableName(int column) throws SQLException {
    throw new SQLFeatureNotSupportedException("Method not supported");
  }

@linux-china linux-china changed the title table name could by not available for Kotlin dataframe JDBC table name could not be available for Kotlin dataframe JDBC May 27, 2025
@linux-china
Copy link
Author

linux-china commented May 27, 2025

BTW, the last Apache Hive JDBC Snapshot uses empty string instead of exception thrown.

  public String getSchemaName(int column) throws SQLException {
    String tableName = getTableName(column);
    int index = tableName.lastIndexOf(DOT);
    if (index >= 0) {
      return tableName.substring(0, index);
    }
    // Impala usually doesn't return fully qualified column names. Return "" to avoid
    // giving false results.
    return "";
  }

  public String getTableName(int column) throws SQLException {
    String columnName = getColumnName(column);
    int index = columnName.lastIndexOf(DOT);
    if (index >= 0) {
      return columnName.substring(0, index);
    }
    return "";
  }

Maybe dataframe could read table name from column with . included.

        val columnName = metaData.getColumnName(i)
        val tableName = try {
            metaData.getTableName(i)
        }   catch (e: Exception) {
            ""
            // get table name from column if `.` included
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy