@@ -58,6 +58,7 @@ private AggregateMetadata(KeyspaceMetadata keyspace, String fullName, String sim
5858 this .stateTypeCodec = stateTypeCodec ;
5959 }
6060
61+ // Cassandra < 3.0:
6162 // CREATE TABLE system.schema_aggregates (
6263 // keyspace_name text,
6364 // aggregate_name text,
@@ -70,42 +71,74 @@ private AggregateMetadata(KeyspaceMetadata keyspace, String fullName, String sim
7071 // state_type text,
7172 // PRIMARY KEY (keyspace_name, aggregate_name, signature)
7273 // ) WITH CLUSTERING ORDER BY (aggregate_name ASC, signature ASC)
73- static AggregateMetadata build (KeyspaceMetadata ksm , Row row , ProtocolVersion protocolVersion , CodecRegistry codecRegistry ) {
74+ //
75+ // Cassandra >= 3.0:
76+ // CREATE TABLE system.schema_aggregates (
77+ // keyspace_name text,
78+ // aggregate_name text,
79+ // argument_types frozen<list<text>>,
80+ // final_func text,
81+ // initcond text,
82+ // return_type text,
83+ // state_func text,
84+ // state_type text,
85+ // PRIMARY KEY (keyspace_name, aggregate_name, argument_types)
86+ // ) WITH CLUSTERING ORDER BY (aggregate_name ASC, argument_types ASC)
87+ static AggregateMetadata build (KeyspaceMetadata ksm , Row row , VersionNumber version , Cluster cluster ) {
88+ CodecRegistry codecRegistry = cluster .getConfiguration ().getCodecRegistry ();
89+ ProtocolVersion protocolVersion = cluster .getConfiguration ().getProtocolOptions ().getProtocolVersion ();
7490 String simpleName = row .getString ("aggregate_name" );
75- List <String > signature = row .getList ("signature" , String .class );
76- String fullName = Metadata .fullFunctionName (simpleName , signature );
77- List <DataType > argumentTypes = parseTypes (row .getList ("argument_types" , String .class ), protocolVersion , codecRegistry );
91+ List <DataType > argumentTypes = parseTypes (ksm , row .getList ("argument_types" , String .class ), version , cluster );
92+ String fullName = Metadata .fullFunctionName (simpleName , argumentTypes );
7893 String finalFuncSimpleName = row .getString ("final_func" );
79- DataType returnType = CassandraTypeParser .parseOne (row .getString ("return_type" ), protocolVersion , codecRegistry );
94+ DataType returnType ;
95+ if (version .getMajor () >= 3 ) {
96+ returnType = DataTypeCqlNameParser .parse (row .getString ("return_type" ), cluster , ksm .getName (), ksm .userTypes , null , false , false );
97+ } else {
98+ returnType = DataTypeClassNameParser .parseOne (row .getString ("return_type" ), protocolVersion , codecRegistry );
99+ }
80100 String stateFuncSimpleName = row .getString ("state_func" );
81101 String stateTypeName = row .getString ("state_type" );
82- DataType stateType = CassandraTypeParser .parseOne (stateTypeName , protocolVersion , codecRegistry );
83- ByteBuffer rawInitCond = row .getBytes ("initcond" );
84- Object initCond = rawInitCond == null ? null : codecRegistry .codecFor (stateType ).deserialize (rawInitCond , protocolVersion );
102+ DataType stateType ;
103+ Object initCond ;
104+ if (version .getMajor () >= 3 ) {
105+ stateType = DataTypeCqlNameParser .parse (stateTypeName , cluster , ksm .getName (), ksm .userTypes , null , false , false );
106+ String rawInitCond = row .getString ("initcond" );
107+ initCond = rawInitCond == null ? null : codecRegistry .codecFor (stateType ).parse (rawInitCond );
108+ } else {
109+ stateType = DataTypeClassNameParser .parseOne (stateTypeName , protocolVersion , codecRegistry );
110+ ByteBuffer rawInitCond = row .getBytes ("initcond" );
111+ initCond = rawInitCond == null ? null : codecRegistry .codecFor (stateType ).deserialize (rawInitCond , protocolVersion );
112+ }
85113
86114 String finalFuncFullName = finalFuncSimpleName == null ? null : String .format ("%s(%s)" , finalFuncSimpleName , stateType );
87- String stateFuncFullName = makeStateFuncFullName (stateFuncSimpleName , stateType . toString (), signature );
115+ String stateFuncFullName = makeStateFuncFullName (stateFuncSimpleName , stateType , argumentTypes );
88116
89- AggregateMetadata aggregate = new AggregateMetadata (ksm , fullName , simpleName , argumentTypes ,
117+ return new AggregateMetadata (ksm , fullName , simpleName , argumentTypes ,
90118 finalFuncSimpleName , finalFuncFullName , initCond , returnType , stateFuncSimpleName ,
91119 stateFuncFullName , stateType , codecRegistry .codecFor (stateType ));
92- ksm .add (aggregate );
93- return aggregate ;
94120 }
95121
96- private static String makeStateFuncFullName (String stateFuncSimpleName , String stateTypeName , List <String > typeNames ) {
97- List <String > args = Lists .newArrayList (stateTypeName );
98- args .addAll (typeNames );
122+ private static String makeStateFuncFullName (String stateFuncSimpleName , DataType stateType , List <DataType > argumentTypes ) {
123+ List <DataType > args = Lists .newArrayList (stateType );
124+ args .addAll (argumentTypes );
99125 return Metadata .fullFunctionName (stateFuncSimpleName , args );
100126 }
101127
102- private static List <DataType > parseTypes (List <String > names , ProtocolVersion protocolVersion , CodecRegistry codecRegistry ) {
103- if (names .isEmpty ())
128+ private static List <DataType > parseTypes (KeyspaceMetadata ksm , List <String > types , VersionNumber version , Cluster cluster ) {
129+ if (types .isEmpty ())
104130 return Collections .emptyList ();
105131
132+ CodecRegistry codecRegistry = cluster .getConfiguration ().getCodecRegistry ();
133+ ProtocolVersion protocolVersion = cluster .getConfiguration ().getProtocolOptions ().getProtocolVersion ();
106134 ImmutableList .Builder <DataType > builder = ImmutableList .builder ();
107- for (String name : names ) {
108- DataType type = CassandraTypeParser .parseOne (name , protocolVersion , codecRegistry );
135+ for (String name : types ) {
136+ DataType type ;
137+ if (version .getMajor () >= 3 ) {
138+ type = DataTypeCqlNameParser .parse (name , cluster , ksm .getName (), ksm .userTypes , null , false , false );
139+ } else {
140+ type = DataTypeClassNameParser .parseOne (name , protocolVersion , codecRegistry );
141+ }
109142 builder .add (type );
110143 }
111144 return builder .build ();
0 commit comments