joao-r-reis commented on code in PR #1915:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1915#discussion_r2462705726


##########
session.go:
##########
@@ -652,114 +653,113 @@ func (s *Session) routingKeyInfo(ctx context.Context, 
stmt string, keyspace stri
        inflight := new(inflightCachedEntry)
        inflight.wg.Add(1)
        defer inflight.wg.Done()
-       s.routingKeyInfoCache.lru.Add(routingKeyInfoCacheKey, inflight)
-       s.routingKeyInfoCache.mu.Unlock()
-
-       var (
-               info         *preparedStatment
-               partitionKey []*ColumnMetadata
-       )
+       s.routingMetadataCache.lru.Add(key, inflight)
+       s.routingMetadataCache.mu.Unlock()
 
-       conn := s.getConn()
-       if conn == nil {
-               // TODO: better error?
-               inflight.err = errors.New("gocql: unable to fetch prepared 
info: no connection available")
-               return nil, inflight.err
-       }
-
-       // get the query info for the statement
-       info, inflight.err = conn.prepareStatement(ctx, stmt, nil, keyspace)
+       var meta StatementMetadata
+       meta, inflight.err = s.StatementMetadata(ctx, stmt, keyspace)
        if inflight.err != nil {
                // don't cache this error
-               s.routingKeyInfoCache.Remove(stmt)
+               s.routingMetadataCache.Remove(key)
                return nil, inflight.err
        }
 
-       // TODO: it would be nice to mark hosts here but as we are not using 
the policies
-       // to fetch hosts we cant
+       inflight.value = &meta
 
-       if info.request.colCount == 0 {
-               // no arguments, no routing key, and no error
-               return nil, nil
-       }
+       return &meta, nil
+}
 
-       table := info.request.table
-       if info.request.keyspace != "" {
-               keyspace = info.request.keyspace
-       }
+// StatementMetadata represents various metadata about a statement.
+type StatementMetadata struct {
+       // Keyspace is the keyspace of the table for the statement.
+       Keyspace string
 
-       if len(info.request.pkeyColumns) > 0 {
-               // proto v4 dont need to calculate primary key columns
-               types := make([]TypeInfo, len(info.request.pkeyColumns))
-               for i, col := range info.request.pkeyColumns {
-                       types[i] = info.request.columns[col].TypeInfo
-               }
+       // Table is the table of the statement.
+       Table string
 
-               routingKeyInfo := &routingKeyInfo{
-                       indexes:  info.request.pkeyColumns,
-                       types:    types,
-                       keyspace: keyspace,
-                       table:    table,
-               }
+       // BindColumns are columns bound to the statement.
+       BindColumns []ColumnInfo
 
-               inflight.value = routingKeyInfo
-               return routingKeyInfo, nil
-       }
+       // PKBindColumnIndexes are the indexes of the BindColumns that 
correspond to
+       // partition key columns. If this is empty then one or more columns in 
the
+       // partition key were not bound to the statement.
+       PKBindColumnIndexes []int
 
-       var keyspaceMetadata *KeyspaceMetadata
-       keyspaceMetadata, inflight.err = 
s.KeyspaceMetadata(info.request.columns[0].Keyspace)
-       if inflight.err != nil {
-               // don't cache this error
-               s.routingKeyInfoCache.Remove(stmt)
-               return nil, inflight.err
+       // ResultColumns are the columns that are returned by the statement.
+       ResultColumns []ColumnInfo
+}
+
+// StatementMetadata returns metadata for a statement. If keyspace is empty,

Review Comment:
   Ok we can keep it like this, we can always discuss caching later if anyone 
requests it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to