[ 
https://issues.apache.org/jira/browse/CASSANDRA-14989?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16749977#comment-16749977
 ] 

Aleksey Yeschenko edited comment on CASSANDRA-14989 at 1/23/19 1:33 PM:
------------------------------------------------------------------------

The patch is fine, but while reviewing it, I noticed a closely related 
pre-existing bug in the logic that has been preserved by this patch.

Specifically, if there is a UDF that's also named {{token}}, and the correct 
keyspace is set via {{USE}} command, then invoking {{token()}} function on a 
table, with all the right arguments, would fail to resolve to the UDF unless 
fully qualified.

{code}
create function test.token(val double) returns null on null input returns int 
language java as 'return 0.0;';
create table test(id int primary key, col double);

select token(col) from test;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Type 
error: col cannot be passed as argument 0 of function system.token of type int"

select token(1.0) from test;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Type 
error: 1.0 cannot be passed as argument 0 of function system.token of type int"
{code}

Using fully-qualified name returns the expected result:
{code}
cqlsh:test> select test.token(1.0) from test;

 test.token(1.0)
-----------------
               0

(1 rows)
cqlsh:test> select test.token(col) from test;

 test.token(col)
-----------------
               0
{code}

However I'm failing to see a reason why non-qualified invocation shouldn't 
follow the general logic of filtering candidate functions for the best match. 
Short-circuiting here, and forcing validation that early seems suboptimal to me.

EDIT: I reckon the same applies to {{fromJson}} and {{toJson}} functions.


was (Author: iamaleksey):
The patch is fine, but while reviewing it, I noticed a closely related 
pre-existing bug in the logic that has been preserved by this patch.

Specifically, if there is a UDF that's also named {{token}}, and the correct 
keyspace is set via {{USE}} command, then invoking {{token()}} function on a 
table, with all the right arguments, would fail to resolve to the UDF unless 
fully qualified.

{code}
create function test.token(val double) returns null on null input returns int 
language java as 'return 0.0;';
create table test(id int primary key, col double);

select token(col) from test;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Type 
error: col cannot be passed as argument 0 of function system.token of type int"

select token(1.0) from test;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Type 
error: 1.0 cannot be passed as argument 0 of function system.token of type int"
{code}

Using fully-qualified name returns the expected result:
{code}
cqlsh:test> select test.token(1.0) from test;

 test.token(1.0)
-----------------
               0

(1 rows)
cqlsh:test> select test.token(col) from test;

 test.token(col)
-----------------
               0
{code}

However I'm failing to see a reason why non-qualified invocation shouldn't 
follow the general logic of filtering candidate functions for the best match. 
Short-circuiting here, and forcing validation that early seems suboptimal to me.

> NullPointerException when SELECTing token() on only one part of a two-part 
> partition key
> ----------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-14989
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-14989
>             Project: Cassandra
>          Issue Type: Bug
>          Components: CQL/Interpreter
>         Environment: Using {{cqlsh 5.0.1}} on a Mac OS X host system with 
> Cassandra 3.11.3 running via Docker for Mac from the official 
> {{cassandra:3.11.3}} image.
>            Reporter: Manuel Kießling
>            Assignee: Dinesh Joshi
>            Priority: Minor
>             Fix For: 4.0, 3.0.x, 3.11.x
>
>
> I have the following schema:
> {code}
> CREATE TABLE query_tests.cart_snapshots (
>     cart_id uuid,
>     realm text,
>     snapshot_id timeuuid,
>     state text,
>     PRIMARY KEY ((cart_id, realm), snapshot_id)
> ) WITH CLUSTERING ORDER BY (snapshot_id DESC)
>     AND bloom_filter_fp_chance = 0.01
>     AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
>     AND comment = ''
>     AND compaction = {'class': 
> 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 
> 'max_threshold': '32', 'min_threshold': '4'}
>     AND compression = {'chunk_length_in_kb': '64', 'class': 
> 'org.apache.cassandra.io.compress.LZ4Compressor'}
>     AND crc_check_chance = 1.0
>     AND dclocal_read_repair_chance = 0.1
>     AND default_time_to_live = 0
>     AND gc_grace_seconds = 864000
>     AND max_index_interval = 2048
>     AND memtable_flush_period_in_ms = 0
>     AND min_index_interval = 128
>     AND read_repair_chance = 0.0
>     AND speculative_retry = '99PERCENTILE';
> {code}
> In cqlsh, I try the following query:
> {code}select token(cart_id) from cart_snapshots ;{code}
> This results in cqlsh returning {{ServerError: 
> java.lang.NullPointerException}}, and the following error in the server log:
> {code}
> DC1N1_1  | ERROR [Native-Transport-Requests-1] 2019-01-16 12:17:52,075 
> QueryMessage.java:129 - Unexpected error during query
> DC1N1_1  | java.lang.NullPointerException: null
> DC1N1_1  |       at 
> org.apache.cassandra.db.marshal.CompositeType.build(CompositeType.java:356) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.db.marshal.CompositeType.build(CompositeType.java:349) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.config.CFMetaData.serializePartitionKey(CFMetaData.java:805)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.functions.TokenFct.execute(TokenFct.java:59) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.selection.ScalarFunctionSelector.getOutput(ScalarFunctionSelector.java:61)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.selection.Selection$SelectionWithProcessing$1.getOutputRow(Selection.java:666)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.selection.Selection$ResultSetBuilder.getOutputRow(Selection.java:492)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.selection.Selection$ResultSetBuilder.newRow(Selection.java:458)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.processPartition(SelectStatement.java:860)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.process(SelectStatement.java:790)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.processResults(SelectStatement.java:438)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:416)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:289)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:117)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:224)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:255) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:240) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.transport.messages.QueryMessage.execute(QueryMessage.java:116)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:517)
>  [apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:410)
>  [apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
>  [netty-all-4.0.44.Final.jar:4.0.44.Final]
> DC1N1_1  |       at 
> io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:357)
>  [netty-all-4.0.44.Final.jar:4.0.44.Final]
> DC1N1_1  |       at 
> io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:35)
>  [netty-all-4.0.44.Final.jar:4.0.44.Final]
> DC1N1_1  |       at 
> io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:348)
>  [netty-all-4.0.44.Final.jar:4.0.44.Final]
> DC1N1_1  |       at 
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
> [na:1.8.0_181]
> DC1N1_1  |       at 
> org.apache.cassandra.concurrent.AbstractLocalAwareExecutorService$FutureTask.run(AbstractLocalAwareExecutorService.java:162)
>  [apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:109) 
> [apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
> DC1N1_1  | ERROR [Native-Transport-Requests-1] 2019-01-16 12:17:52,076 
> ErrorMessage.java:384 - Unexpected exception during request
> DC1N1_1  | java.lang.NullPointerException: null
> DC1N1_1  |       at 
> org.apache.cassandra.db.marshal.CompositeType.build(CompositeType.java:356) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.db.marshal.CompositeType.build(CompositeType.java:349) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.config.CFMetaData.serializePartitionKey(CFMetaData.java:805)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.functions.TokenFct.execute(TokenFct.java:59) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.selection.ScalarFunctionSelector.getOutput(ScalarFunctionSelector.java:61)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.selection.Selection$SelectionWithProcessing$1.getOutputRow(Selection.java:666)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.selection.Selection$ResultSetBuilder.getOutputRow(Selection.java:492)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.selection.Selection$ResultSetBuilder.newRow(Selection.java:458)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.processPartition(SelectStatement.java:860)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.process(SelectStatement.java:790)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.processResults(SelectStatement.java:438)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:416)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:289)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:117)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:224)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:255) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:240) 
> ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.transport.messages.QueryMessage.execute(QueryMessage.java:116)
>  ~[apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:517)
>  [apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.transport.Message$Dispatcher.channelRead0(Message.java:410)
>  [apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
>  [netty-all-4.0.44.Final.jar:4.0.44.Final]
> DC1N1_1  |       at 
> io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:357)
>  [netty-all-4.0.44.Final.jar:4.0.44.Final]
> DC1N1_1  |       at 
> io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:35)
>  [netty-all-4.0.44.Final.jar:4.0.44.Final]
> DC1N1_1  |       at 
> io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:348)
>  [netty-all-4.0.44.Final.jar:4.0.44.Final]
> DC1N1_1  |       at 
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
> [na:1.8.0_181]
> DC1N1_1  |       at 
> org.apache.cassandra.concurrent.AbstractLocalAwareExecutorService$FutureTask.run(AbstractLocalAwareExecutorService.java:162)
>  [apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at 
> org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:109) 
> [apache-cassandra-3.11.3.jar:3.11.3]
> DC1N1_1  |       at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to