mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
* Fix formatting in CLI results with custom SQLResonse.UnmarshalJSON
When I started this, it was meant to be a quick fix to address the confusing
result formats we were seeing in the CLI. For example, all large integer values
were displayed in scientifc notation. This is because we were passing the result
types from JSON (in this case, float64) into pretty print. Similarly, `IDSets`
and `StringSets` where being printed using the default go Stringer for the types
[]int64 and []string respectively.
I started by writing a customer UnmarshalJSON() method for the `SQLResponse`
type. Part of this (the part which converts data types based on header types)
was already being used in dax tests, so this just formalizes that logic as part
of the `SQLResponse` type.
Then I realized that the sql3 tests (run against the `sql3` package) were
failing because sql3 is not actually returning the `IDSets` and `StringSets`
types. A future task is to formalize return types, define them, and modify sql3
to return them. Once that is done, we can remove the "typed" switch in the
`SQLResponse` json unmarshaller.
Another significant change is the modification to the `ExprDataType` interface:
```
type ExprDataType interface {
exprDataType()
TypeName() string
TypeDescription() string
TypeInfo() map[string]interface{}
}
```
I added two more methods in order to distinguish between a type (`DECIMAL`), its
description (`DECIMAL(2)`), and its type info (`"scale": int64(2)`). Currently,
the description can be used as the field definition in a CREATE TABLE statement,
but we may want to re-think that. Also, Decimal is the only type currently using
TypeInfo.
Finally, I tried to consilidate things around `dax.FieldType` instead of
comparing against parser types outside of sql3. We still have some sql3 parser
and planner types lurking about, but we can address those in future commits.
* Add some test coverage
* smoke test expected INT, now int
* minor fixes
* Introduce WireQueryResponse and related types
This also changes dax.FieldType to dax.BaseType.
* Populate WireQueryResponse correctly
Currently this is in the http handler, and in the queryer.
* Convert sql3 and dax tests to expect pilosa.WireQueryField in results
* fix PQL tests in the SQL defs
* Address a few of the skipped sql tests in dax
203 lines
4.7 KiB
Go
203 lines
4.7 KiB
Go
package defs
|
|
|
|
// BETWEEN tests
|
|
var betweenTests = TableTest{
|
|
Table: tbl(
|
|
"between_all_types",
|
|
srcHdrs(
|
|
srcHdr("_id", fldTypeID),
|
|
srcHdr("i1", fldTypeInt, "min 0", "max 1000"),
|
|
srcHdr("b1", fldTypeBool),
|
|
srcHdr("d1", fldTypeDecimal2),
|
|
srcHdr("id1", fldTypeID),
|
|
srcHdr("ids1", fldTypeIDSet),
|
|
srcHdr("s1", fldTypeString),
|
|
srcHdr("ss1", fldTypeStringSet),
|
|
srcHdr("t1", fldTypeTimestamp),
|
|
),
|
|
srcRows(
|
|
srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()),
|
|
),
|
|
),
|
|
SQLTests: []SQLTest{
|
|
{
|
|
SQLs: sqls(
|
|
"select _id between 1 and 10 from between_all_types",
|
|
),
|
|
ExpHdrs: hdrs(
|
|
hdr("", fldTypeBool),
|
|
),
|
|
ExpRows: rows(
|
|
row(bool(true)),
|
|
),
|
|
Compare: CompareExactUnordered,
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select i1 between 1 and 10 from between_all_types",
|
|
),
|
|
ExpHdrs: hdrs(
|
|
hdr("", fldTypeBool),
|
|
),
|
|
ExpRows: rows(
|
|
row(bool(false)),
|
|
),
|
|
Compare: CompareExactUnordered,
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select b1 between true and false from between_all_types",
|
|
),
|
|
ExpErr: "type 'BOOL' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select d1 between 1.23 and 4.56 from between_all_types",
|
|
),
|
|
ExpErr: "type 'DECIMAL(2)' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select id1 between 3 and 7 from between_all_types",
|
|
),
|
|
ExpHdrs: hdrs(
|
|
hdr("", fldTypeBool),
|
|
),
|
|
ExpRows: rows(
|
|
row(bool(false)),
|
|
),
|
|
Compare: CompareExactUnordered,
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select ids1 between [100, 102] and [456, 789] from between_all_types",
|
|
),
|
|
ExpErr: "type 'IDSET' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select s1 between 'foo' and 'bar' from between_all_types",
|
|
),
|
|
ExpErr: "type 'STRING' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select ss1 between ['a', 'b'] and ['c', 'd'] from between_all_types",
|
|
),
|
|
ExpErr: "type 'STRINGSET' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select t1 between '2010-11-01T22:08:41+00:00' and '2013-11-01T22:08:41+00:00' from between_all_types",
|
|
),
|
|
ExpHdrs: hdrs(
|
|
hdr("", fldTypeBool),
|
|
),
|
|
ExpRows: rows(
|
|
row(bool(true)),
|
|
),
|
|
Compare: CompareExactUnordered,
|
|
},
|
|
},
|
|
}
|
|
|
|
// NOT BETWEEN tests
|
|
var notBetweenTests = TableTest{
|
|
Table: tbl(
|
|
"not_between_all_types",
|
|
srcHdrs(
|
|
srcHdr("_id", fldTypeID),
|
|
srcHdr("i1", fldTypeInt, "min 0", "max 1000"),
|
|
srcHdr("b1", fldTypeBool),
|
|
srcHdr("d1", fldTypeDecimal2),
|
|
srcHdr("id1", fldTypeID),
|
|
srcHdr("ids1", fldTypeIDSet),
|
|
srcHdr("s1", fldTypeString),
|
|
srcHdr("ss1", fldTypeStringSet),
|
|
srcHdr("t1", fldTypeTimestamp),
|
|
),
|
|
srcRows(
|
|
srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()),
|
|
),
|
|
),
|
|
SQLTests: []SQLTest{
|
|
{
|
|
SQLs: sqls(
|
|
"select _id not between 1 and 10 from not_between_all_types",
|
|
),
|
|
ExpHdrs: hdrs(
|
|
hdr("", fldTypeBool),
|
|
),
|
|
ExpRows: rows(
|
|
row(bool(false)),
|
|
),
|
|
Compare: CompareExactUnordered,
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select i1 not between 1 and 10 from not_between_all_types",
|
|
),
|
|
ExpHdrs: hdrs(
|
|
hdr("", fldTypeBool),
|
|
),
|
|
ExpRows: rows(
|
|
row(bool(true)),
|
|
),
|
|
Compare: CompareExactUnordered,
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select b1 not between true and false from not_between_all_types",
|
|
),
|
|
ExpErr: "type 'BOOL' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select d1 not between 1.23 and 4.56 from not_between_all_types",
|
|
),
|
|
ExpErr: "type 'DECIMAL(2)' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select id1 between 3 and 7 from not_between_all_types",
|
|
),
|
|
ExpHdrs: hdrs(
|
|
hdr("", fldTypeBool),
|
|
),
|
|
ExpRows: rows(
|
|
row(bool(false)),
|
|
),
|
|
Compare: CompareExactUnordered,
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select ids1 not between [100, 102] and [456, 789] from not_between_all_types",
|
|
),
|
|
ExpErr: "type 'IDSET' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select s1 not between 'foo' and 'bar' from not_between_all_types",
|
|
),
|
|
ExpErr: "type 'STRING' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select ss1 not between ['a', 'b'] and ['c', 'd'] from not_between_all_types",
|
|
),
|
|
ExpErr: "type 'STRINGSET' cannot be used as a range subscript",
|
|
},
|
|
{
|
|
SQLs: sqls(
|
|
"select t1 not between '2010-11-01T22:08:41+00:00' and '2013-11-01T22:08:41+00:00' from not_between_all_types",
|
|
),
|
|
ExpHdrs: hdrs(
|
|
hdr("", fldTypeBool),
|
|
),
|
|
ExpRows: rows(
|
|
row(bool(false)),
|
|
),
|
|
Compare: CompareExactUnordered,
|
|
},
|
|
},
|
|
}
|