Inconsistent column type when a TEXT column retrieved from TableMetadata and ColumnDefinitions

8 views
Skip to first unread message

Hiroyuki Yamada

unread,
Jan 23, 2018, 10:40:29 PM1/23/18
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

I got some inconsistent column type from TableMetadata and ColumnDefinitions (Row) when the column is defined as TEXT.

Let's assume "c1" is defined as TEXT,
and when I get from TableMetadata,
it will return TEXT type as followings.

tableMetadata.getColumn("c1").getType().getName() -> TEXT type

But, when I get from ColumnDefinitions (or Row) like the following way.
it will return varchar.

row.getColumnDefinitions().getType("c1").getName() -> varchar type

It seems like a simple bug, but I haven't gone deeper into the code.
If it is, it would be great if it can be fixed soon.

Thanks,
Hiroyuki

Andy Tolbert

unread,
Jan 23, 2018, 11:04:00 PM1/23/18
to java-dri...@lists.datastax.com
Hi Hiroyuki,

I suspect what is happening here that as of C* 2.1 with Native Protocol V3 (what the driver uses to communicate with C*) the 'text' column type type no longer exists, instead 'varchar' type is always returned for text and varchar columns.

However in CQL, 'text' and 'varchar' are still treated as different types, likely for backwards compatibility reasons.  When you use TableMetadata.getColumn, we are accessing the table schema as it is stored in C* which contains CQL references.  When you use Row.getColumnDefinitions, you are accessing data returned from the native protocol.

Conceptually, 'text' is just an alias for 'varchar' so this should not be of concern, but that is not very clear.  Perhaps in the next major version of the driver (4.0), we will should consider always returning varchar for TableMetadata column data types, whether it is a text or varchar as they are functionally the same thing.

Thanks,
Andy

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
Reply all
Reply to author
Forward
0 new messages