Skip to content

Map Cassandra INET to Trino IPADDRESS type#13068

Merged
ebyhr merged 3 commits intotrinodb:masterfrom
chen-ni:issue-851-task-2
Jul 12, 2022
Merged

Map Cassandra INET to Trino IPADDRESS type#13068
ebyhr merged 3 commits intotrinodb:masterfrom
chen-ni:issue-851-task-2

Conversation

@chen-ni
Copy link
Copy Markdown
Contributor

@chen-ni chen-ni commented Jul 3, 2022

Description

Is this change a fix, improvement, new feature, refactoring, or other?

An improvement in type mapping. We used to map Cassandra INET type to Trino VARCHAR. It would be better to map it to Trino IPADDRESS.

Due to the fact that IpAddressType is not located in io.trino.spi.type, we have to use typeManager().getType() to get the type reference (please refer to this discussion).

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

The Cassandra connector.

How would you describe this change to a non-technical end user or system administrator?

By mapping the Cassandra INET to Trino IPADDRESS type, when reading INET data in Cassandra, we can apply IP Address Functions without the need for casting.

Related issues, pull requests, and links

Fix #851.

I've referred to the 2 following PRs:

Documentation

( ) No documentation is needed.
(x) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

( ) No release notes entries required.
( ) Release notes entries required with the following suggested text:

# Cassandra
* Map Cassandra `inet` type to Trino `ipaddress` type. ({issue}`851`)

@findinpath
Copy link
Copy Markdown
Contributor

Pls remove the first two commits (they are useless if the second one reverts the first one).

@findinpath
Copy link
Copy Markdown
Contributor

Please do take some time to fill in the response about the question:

How would you describe this change to a non-technical end user or system administrator?

Copy link
Copy Markdown
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to know if this approach is promising.

You can refactor CassandraTypes first to graduate static type mapping. We wanted to make the mapping dynamic for LIST, MAP and SET type either.

Copy link
Copy Markdown
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update "Data types" in cassandra.rst. Thanks for your contribution.

@chen-ni
Copy link
Copy Markdown
Contributor Author

chen-ni commented Jul 4, 2022

You can refactor CassandraTypes first to graduate static type mapping.

@ebyhr Thanks for the helpful suggestion!

To move away from the static type mapping pattern, the simplest approach I can think of is just to make those fields non-static, initialize them from the constructor (and maybe add some builders later to allow dynamically getting type mappings) and access those type mappings through an instance of CassandraTypes.

Is this what's expected? Or is some bigger change expected?

@github-actions github-actions bot added the docs label Jul 4, 2022
@chen-ni chen-ni marked this pull request as ready for review July 6, 2022 00:04
@chen-ni chen-ni requested review from ebyhr and findinpath July 6, 2022 00:04
Copy link
Copy Markdown
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what's expected? Or is some bigger change expected?

I expect larger change. We shouldn't initialize a CassandraTypes variable from CassandraMetadata.

@chen-ni
Copy link
Copy Markdown
Contributor Author

chen-ni commented Jul 6, 2022

We shouldn't initialize a CassandraTypes variable from CassandraMetadata.

@ebyhr I agree. I'm trying to figure out how to avoid it, but it seems a little difficult.

The biggest problem is how to get a typeManager instance in the static context of CassandraTypes. Perhaps we could consider using static injection in Guice? But it's not a recommended approach either.

As for the refactoring you suggested earlier:

You can refactor CassandraTypes first to graduate static type mapping.

I'm still not sure which kind of refactoring is expected. I'll keep trying, but it would be great if you could shed some light on it when possible :)

Anyway, now that the tests pass, I'll keep refactoring until it's acceptable.

@chen-ni
Copy link
Copy Markdown
Contributor Author

chen-ni commented Jul 6, 2022

@ebyhr I just removed the static INET type in CassandraTypes altogether. Please check if this approach is acceptable. Thanks!

@chen-ni chen-ni requested review from ebyhr, findinpath and tangjiangling and removed request for ebyhr, findinpath and tangjiangling July 6, 2022 23:44
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: separate commit CassandraType.toCassandraType -> toCassandraType

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findinpath Sorry, I don't quite understand here. What do we need to put in the separate commit? A change to static import?

@chen-ni chen-ni removed the request for review from tangjiangling July 11, 2022 07:54
@chen-ni chen-ni requested a review from findinpath July 12, 2022 00:04
@ebyhr ebyhr merged commit 3494e12 into trinodb:master Jul 12, 2022
@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Jul 12, 2022

Merged, thanks!

@ebyhr ebyhr mentioned this pull request Jul 12, 2022
@github-actions github-actions bot added this to the 390 milestone Jul 12, 2022
@chen-ni
Copy link
Copy Markdown
Contributor Author

chen-ni commented Jul 12, 2022

@ebyhr Sorry, just realized I didn't remove the outdated static INET type here:

public static final CassandraType INET = new CassandraType(Kind.INET, createVarcharType(IP_ADDRESS_STRING_MAX_LENGTH));

It was indeed removed in the original commit but the change must have been lost while resolving a conflict during one of the fixes later.

Should I create a simple PR to remove it or it's fine to leave it like this for a while?

P.S. Thanks for the helpful code reviews and refactoring example :)

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Jul 12, 2022

@chen-ni You can send another PR. Thanks for finding that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Map Cassandra INET & UUID to Trino IPADDRESS & UUID

3 participants