Is there any way to map the keyspace attribute on the UDT annotation?

9 views
Skip to first unread message

Adrian Cole

unread,
Feb 19, 2018, 9:13:11 AM2/19/18
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi, there.

We use your driver in Zipkin, which is a distributed tracing system. Particularly in our most recent schema, we take advantage of UDTs for things like service endpoints.
We bake-in a schema with indexing, and by default everything goes to "zipkin2". Users can override this, and by basic string templating, we'll use whatever they want.

There's a glitch with the UDTs, because they are mapped with an annotation attribute:

@UDT(keyspace = "zipkin2_udts", name = "endpoint")
static final class EndpointUDT {

So, as far as we know, we *also* have to install the schema to whatever the annotation says, then do a dance like below to remap it later:

    TypeCodec<EndpointUDT> endpointCodec = mapping.udtCodec(EndpointUDT.class);

    KeyspaceMetadata keyspace =
        session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace());

    session.getCluster().getConfiguration().getCodecRegistry()
      .register(
        new TypeCodecImpl<>(keyspace.getUserType("endpoint"), EndpointUDT.class, endpointCodec))

When people look at our schema they are surprised to see the *extra* copy of it "zipkin2_udts", and in
some cases they can't install something like this anyway. For example, their team may have a naming
policy that requires a prefix.

I was hoping that 3.4 would fix this, but it looks like the new mapping functionality doesn't work for UDTs

So, anyway we have some users who literally can't use cassandra due to this, so looking for a way out.
Is there some other way to register a java type mapped to a UDT without relying on anything hard-coded?
Perhaps a mapping? I'm getting desperate enough to try and generate the annotation at runtime :)

-A
Reply all
Reply to author
Forward
0 new messages