CategoricalData / CQL

Categorical Query Language IDE
http://categoricaldata.net
299 stars 22 forks source link

Correct handling of nullable typeside functions #54

Closed o1lo01ol1o closed 3 years ago

o1lo01ol1o commented 4 years ago

I'm aware that the following function could be wrapped in an Option type, but I'm not sure how to then get that back to an SQL null when the db is exported as I don't believe this is covered in the documentation. Simply returning null made sigma_chase complain (though I have not tried any of the other functions). How should this be handled?

asDouble : Varchar -> Decimal ="
           switch (input[0]) {
            case 'NA': return java.math.BigDecimal.valueOf(0.0) // how to make this null?
            default: return java.math.BigDecimal.valueOf(parseFloat(input[0]))
           }
        " 
wisnesky commented 4 years ago

That’s a good question. So far, everyone who has done an SQL export has done so on the SQL typeside, and so exported non-option valued attributes, which CQL can examine for being ‘ground’ in the type algebra and emit as nulls appropriately. But it makes just as much sense to export a CQL database with option-sql-typed attributes, and I can’t really think of a good reason to convert to non-option valued attributes to option-valued just for export. Let me add an alternative SQL export command that works in this manner and get back to you soon.

On Aug 4, 2020, at 5:10 AM, Tim Pierson notifications@github.com wrote:

I'm aware that the following function could be wrapped in an Option type, but I'm not sure how to then get that back to an SQL null when the db is exported as I don't believe this is covered in the documentation. Simply returning null made sigma_chase complain (though I have not tried any of the other functions). How should this be handled?

asDouble : Varchar -> Decimal =" switch (input[0]) { case 'NA': return java.math.BigDecimal.valueOf(0.0) // how to make this null? default: return java.math.BigDecimal.valueOf(parseFloat(input[0])) } " — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CategoricalData/CQL/issues/54, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2QKN6PGYHRBUYECV5HUYLR673CXANCNFSM4PUKTK5Q.

wisnesky commented 3 years ago

The 2021 version of CQL now exclusively uses option-valued attributes in the "sql" typeside, rather than labelled nulls, which as you saw were definitely not the right semantics for SQL interaction. I think this issue is closed in spirit, and I would be happy to try your examples again.