Problem with float in frozen type

9 views
Skip to first unread message

Niclas Hedhman

unread,
Jan 31, 2023, 6:22:27 AM1/31/23
to gocql

I have a datatype;

CREATE TYPE IF NOT EXISTS ks.processing (
    unit text,
    scaling text,
    k double,
    m double,
    min double,
    max double,
    condition text,
    scalefunc text
);

which is used in table defined as

type Processing struct {
    Unit string      `json:"unit"`
    Scaling Scaling  `json:"scaling"`
    K float64        `json:"k"`
    M float64        `json:"m"`
    Min float64      `json:"min"`
    Max float64      `json:"max"`
    Condition string `json:"condition"`
    ScaleFunc string `json:"scalefunc"`
}



And for a given stored field, such as

{unit: '˚C', scaling: 'lin', k:1.1, m: 10, min: 15, max: 30, condition: null, scalefunc: null}

I read that with GoCQL, using Scanner (irrelevant parts not provided);


const datapointQuery = "SELECT project,subsystem,name,pollinterval,datasourcetype,timetolive,proc,ttnv3,web,mqtt FROM %s.%s WHERE orgid = ? AND project = ? AND subsystem = ? AND name = ? AND DELETED = '1970-01-01 0:00:00+0000' ALLOW FILTERING;"


func (cass *CassandraClient) GetDatapoint(org int64, projectName string, subsystemName string, datapoint string) (model.DatapointSettings, error) {
    iter := cass.createQuery(datapointsTablename, datapointQuery, org, projectName, subsystemName, datapoint)
    scanner := iter.Scanner()
    for scanner.Next() {
        return cass.deserializeDatapointRow(scanner), iter.Close()
    }
    return model.DatapointSettings{}, iter.Close()
}


func (cass *CassandraClient) createQuery(tableName string, query string, args ...interface{}) *gocql.Iter {
    t := fmt.Sprintf(query, cass.clusterConfig.Keyspace, tableName)
    q := cass.session.Query(t).Consistency(gocql.One).Idempotent(true).Bind(args...)
    return q.Iter()
}

func (cass *CassandraClient) deserializeDatapointRow(scanner gocql.Scanner) model.DatapointSettings {
    var r model.DatapointSettings
    var ttnv3 model.Ttnv3Datasource
    var web model.WebDatasource
    var mqtt model.MqttDatasource
    var proc model.Processing
    err := scanner.Scan(&r.Project, &r.Subsystem, &r.Name, &r.Interval, &r.SourceType, &r.TimeToLive, &proc, &ttnv3, &web, &mqtt)
    log.DefaultLogger.Info(fmt.Sprintf("Datapoint: %+v", r))
    log.DefaultLogger.Info(fmt.Sprintf("Processing: %+v", proc))
    r.Proc = proc
    :


msg="Processing: {Unit:˚C Scaling:lin K:1.1 M:10 Min:0 Max:0 Condition: ScaleFunc:}"




So, the problem I am seeing is that "k" and "m" is deserialized to the "Processing" instance, but "min" and "max" becomes "0". And I am running out of ideas of what could possibly be wrong. From my PoV, I can't see any difference between "k" and "m" vs "min" and "max", yet I observe very different behavior.

Any ideas?

Cheers
Niclas
Reply all
Reply to author
Forward
0 new messages