Skip to content

JDBC connector fails for DB2 views using SESSION_USER or DB2 native functions #27814

@KNagaVivek

Description

@KNagaVivek

The DB2 JDBC connector currently reads DB2 views using getViews() and Presto tries to analyze the view SQL as Presto SQL.

This causes problems when the DB2 view contains DB2-specific functions or keywords like:

  • SESSION_USER
  • DB2 UDFs
  • other DB2 native SQL functions

Example error:

Query failed: Failed analyzing stored view '<catalog>.<schema>.<view>':
Column 'session_user' cannot be resolved

Expected Behavior or Use Case

Presto should allow DB2 to execute the view directly instead of re-analyzing the view SQL.

This would allow DB2 to correctly handle:

  • SESSION_USER
  • DB2 UDFs
  • security logic inside views
  • DB2-specific SQL syntax

Current Behavior

Today the connector gets the view definition from DB2 and Presto re-processes the SQL internally.
Because of this:

  • DB2 functions are not recognized
  • SESSION_USER is treated like a column name
  • DB2 UDFs fail to resolve
  • views containing DB2-specific logic cannot be queried

This also creates differences between querying the same view from:

  • native DB2 clients (works)
  • Presto JDBC connector (fails)

Root Cause

Current flow:

DB2 view
  -> JdbcMetadata.getViews()
  -> ConnectorViewDefinition
  -> StatementAnalyzer.analyzeView()
  -> Presto analyzes DB2 SQL as Presto SQL

The problem is that DB2 SQL dialect is being analyzed using Presto SQL rules.

Possible Implementation

Add one property to BaseJdbcConfig controlling view resolution for all JDBC connectors

Example Screenshots (if appropriate):

Context

This issue affects views that rely on database-native functions, session context, or security logic implemented in the remote database.

The same views work correctly when queried directly from DB2 clients, but fail when accessed through the Presto JDBC connector.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions