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

Bohdan Siryk commented on CASSGO-105:
-------------------------------------

To reproduce:

 
{code:java}
func main() {
        cluster := gocql.NewCluster("127.0.0.1")
        cluster.Keyspace = "testks"
        session, err := cluster.CreateSession()
        if err != nil {
                panic(err)
        }
        defer session.Close()
        fmt.Println("Connected to Cassandra successfully!")
        // Creating custom function
        err = session.Query(`CREATE FUNCTION testks.my_function ( state 
tuple<int,bigint>, val int )            
  CALLED ON NULL INPUT            
  RETURNS tuple<int,bigint>            
  LANGUAGE java AS            
  $$if (val !=null) {                
  state.setInt(0, state.getInt(0)+1);                 
  state.setLong(1, state.getLong(1)+val.intValue());            
  }            
  return state;$$;`).Exec()
        if err != nil {
                panic(err)
        }
        fmt.Println("Custom function created successfully!")
        // Creating custom aggregate
        err = session.Query(`CREATE AGGREGATE testks.my_aggregate (int)         
   
  SFUNC my_function            
  STYPE tuple<int,bigint>            
  INITCOND (0,0);`).Exec()
        if err != nil {
                panic(err)
        }
        fmt.Println("Custom aggregate created successfully!")
        _, err = session.KeyspaceMetadata("testks")
        if err != nil {
                panic(err)
        }
}
{code}
 

 

> Nil pointer dereference in compileMetadata when custom aggregate has no final 
> func defined
> ------------------------------------------------------------------------------------------
>
>                 Key: CASSGO-105
>                 URL: https://issues.apache.org/jira/browse/CASSGO-105
>             Project: Apache Cassandra Go driver
>          Issue Type: Bug
>            Reporter: Bohdan Siryk
>            Priority: Normal
>
> A nil pointer dereference occurs when a custom aggregate is defined without a 
> FINALFUNC. Cassandra states that the final func is optional, so Gocql should 
> correctly handle such a case.
> Discovered during the implementation of CASSGO-101.
> The root cause is [this piece of 
> code|https://github.com/apache/cassandra-gocql-driver/blob/f1e31a58f7e0c25e58e2e2a0a0c6de358e643e8b/metadata.go#L362],
>  which tries to get function metadata from the Functions map by finalFunc 
> name. As there is no final function for the created aggregate, 
> _AggregateMetadata.finalFunc_ is an empty string. Trying to get the function 
> metadata from _KeyspaceMetadata.Functions_ map by that empty string value 
> result in a return of a nil value, which is being dereferenced after.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to