Skip to content

Encoding problem with column names using Amazon Athena ODBC 2.x driver #10

@jeffsantos

Description

@jeffsantos

I'm trying to run a query on a database using the Amazon Athena ODBC 2.x driver (https://docs.aws.amazon.com/athena/latest/ug/odbc-v2-driver.html). I can correctly connect to the Athena server (via DSN) and also execute queries. The problem is that the returned column names appear to be in the wrong encoding system. The contents of the columns themselves are correct, the problem is only in the name of the columns.

The Athena driver requires forwardOnly cursors, so I used the query:forwardOnly: message from the connection object to execute the queries. I debugged the execution of this message and identified the following:

  1. As I am using Windows, the ODBCConnection object is always instantiated with utf-16 as the string encoding system. This is done in the ODBCConnection class >> determineStringEncoder which always returns an instance of ODBCUTF16Encoder.

  2. When executing the query, the problem occurs in the method
    ODBCAbstractStatement >> describeCols:

This is the part of the code where the problem occurs:

col := ODBCColAttr new
columnNumber: each;
name: (self stringEncoder decodeStringFrom: name characterCount: colNameLen value);
type: dataType value;
precision: columnSize value;
scale: decimalDigits value;
yourself. 

I can get the proper column names using other odbc libraries (pyodbc for Python, for example).

I tried to understand how the ODBCUTF16Encoder >> decodeStringFrom:characterCount: method works, but it is very complicated, and I still haven't been able to understand what might be happening. I would appreciate it if you have any tips that could help me.

This is a screenshot of my playground inspecting an ODBCRow object returned by the query where the problem can be seen more clearly:

odbc-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions