Commit graph

154 commits

Author SHA1 Message Date
Lory Cloutier
ad5f1d4eaa
Add test coverage in compilebulkinsert.go (#2353)
Assignment compatibility checking in analyzeBulkInsertStatement is
now tested. This isn't checking the values themselves, it's there
to make sure the structure is correct for mapping values to columns.
2023-03-27 17:01:59 -05:00
Seebs
f4905891d4 unbreak nested joins
It turns out that the problem with nested joins was that we were
trying to cleverly invert them, but that seems to be incorrect and
resulted in incorrect nesting.

The test case for this is
	SELECT * FROM X INNER JOIN Y ON true INNER JOIN Z ON false
this is now parsed as
	(X inner join Y on true) inner join z on false

Which, as it turns out, is the structure that stringizes back to the
original statement.

We were previously parsing it as
	X inner join (y inner join z on false) on true
which stringizes out to a different form, and is also, I think,
just straightforwardly not what we want.

So basically, we had special case code to recognize that we
were doing a join on top of another join, and invert them in
some way, and I have no idea why because that seems not to be
correct, or at least, it produces nonsensical stringizing that
we can't then parse.
2023-03-27 16:56:29 -05:00
Seebs
3f7ae75e17 increase parser test coverage significantly
We now test the tuple-assignment at all, although it's
perhaps confusing because we expect a ()-list of columns
to go with a {}-list of values. We also test a lot more
errors and some more successes, and additional literal types
in mustParseLiteral.
2023-03-27 16:56:29 -05:00
Seebs
d4fb807664 drop unused isHex and IsInteger functions 2023-03-27 16:56:29 -05:00
Lory Cloutier
d114680222
Add SQL3 test coverage for expressionagg.go (#2351)
FB-2045
aggregate{Avg,Min,Max}->Update now tested for DataTypeDecimal.
{avg,min,max}PlanExpression->WithChildren now tested.
percentilePlanExpression->{Evaluate,Plan,WithChildren} is not
tested because percentile gets sent directly to PQL rather than
getting planned and evaluated in SQL.
aggregateLast->everything is not tested because Last is not yet
completely implemented.
2023-03-27 12:00:47 -05:00
Seebs
f12587f414 handle null results gracefully in SetContains{Any,All}
SetContains returns null if either of the values it's given
is null. SetContainsAny and SetContainsAll should also do this.
2023-03-24 16:01:09 -05:00
Seebs
54dbeec1af support null/non-null tests for non-BSI fields
There's a lot going on here. First, we were treating "the test is
a Condition" as implying BSI, which it doesn't anymore. Second, the
behavior of conditions was weird and BSI-specific. Third, we had
to propagate these changes and features throughout a bunch of code,
including both the core featurebase code and the DAX replacements/copies
of it, plus the SQL3 layer.

We refactor this so that tests for equality and inequality work for
non-BSI fields, so now if you accidentally use `==` in a Row call
on a non-BSI field, it still works; that's not specific to BSI
fields anymore.

We add a TrackExistence flag to fields, and propagate it through
things like our protobuf code, etcetera, so that we can successfully
create fields. Newly-created fields get this by default, because
we add it unconditionally to them, but the paths that are being
called with existing fields don't add it. So, when we "create"
(really, just load the definition of) a field from something stored
in the schema, we don't add TrackExistence to it, but any path to
creating a new field should.

A time quantum field with NoStandardView will *effectively*
lack TrackExistence.

For sets, mutexes, and time quantums with a standard view, anything
that sets bits will also set a corresponding bit for the record in
a new "existence" view. This allows us to distinguish between an
empty set and a null, and also allows null checks to be constant-time.

When clearing bits, we don't clear existence bits EXCEPT that if
you clear a bit in a mutex, *and the bit actually existed*, we clear
the existence bit. For sets and time quantums, clearing bits never
clears the existence bit.

Deleting records clears the existence bit.

We also add code to the `batch` subpackage to generate suitable
existence field bitmaps and import them. This logic correctly handles
empty sets and nils. The `batch` package does not allow specification
of anything equivalent to clearing a single bit from an existing
record, so we don't have to deal with the mutex complexity in that
case, which is good because it would be impossible.

This requires a number of other subtle changes, such as allowing
new fields to have more than one FieldOption specified for them.

We also drop the handful of implementation bits relating to the
"fullySorted" internal-use-only import flag, which existed only to
support the JSON ingest API, which we've removed.

The most dangerous part of this is that the mutex semantics are
impossible to implement on top of our existing API, because they
require us to know, not how *many* bits we cleared, but which
*specific* bits we cleared. I've implemented this as a new Tx method,
which is almost certainly going to be tech debt one day; if we some
day drop the Import API, we should remove that.

The testing for this is only currently covering the Set/Clear
behavior of PQL, and the Import API. The batch tests haven't been
written yet.

Fields that don't have existence tracking enabled refuse to perform
null/not-null tests. They should also report themselves as having
no null values -- if a record exists, sets in it are considered
empty rather than null.

The SQL3 support requires a number of subtle modifications to both
featurebase and some addon tooling. The essential thing is dropping
the unconditional translation of nil slices to non-nil empty slices
in translateResult, both in the executor and the orchestrator. We
also modify the logic that handles generating results from Extract
calls, to ensure that non-null sets get an empty slice created for
them even if they never have any values assigned.

The expected results for some tests are different now; we expect to
get nil slices, rather than 0-length non-nil slices, for fields which
were never written for a given record. Most tests were not changed.
(In every case, if a test was failing, I actually checked the logic
before changing expected results. This required a lot of tracking down
of edge cases.)

The batch package now rejects as an error attempts to clear single
bits from mutex fields, because so far as I can tell it's simply
impossible to have a roaring import that specifies the correct semantics
there; you can't tell whether to clear an existence bit without
access to the currently-set bits, which the batch API doesn't have.
We already supported the special case of specifying a clear value
of nil for clearing a mutex field; now that is the only allowed
value for a mutex field to have in row.Clears.

We change the logic for fixing up incoming view names (in two places)
to stop assuming that any view in a time field other than "" that does
not have viewStandard as a prefix is a partial time quantum name that
should have "standard_" prepended to it. This allows us to submit
bitmaps for "existence" to time quantum fields and not have them
silently transformed into "standard_existence" because that's what we'd
do with "202203".

We drop the field ClearBits method, which was totally unused.

We drop the sliceDifference function, which was used in a previous
mutex implementation and hasn't been used in ages, and the test
case for it, and the helper function used only by that test case.
2023-03-24 16:01:09 -05:00
tgruben
bc07fb4a96
SQL3 Test Coverage: complete coerceValue coverage (#2343)
* complete coereceVal test coverage

* sql between test

* optimized between operator

* basic operator test
2023-03-24 13:33:05 -05:00
Lory Cloutier
fc74c8ecde
Add tests cases for coverage in expressiontypes.go (#2345)
FB-2041
Added tests for typeIsTimeQuantum and typeIsSet and made them pass.
Added tests for DataTypeTuple cases in typesAreAssignmentCompatible.
Timestamp conversion checking is handled before it gets to that
point but I left those branches in as a backstop.
Checking to see if DataType[String,ID]SetQuantum can be assigned
to themselves doesn't appear to be reachable currently but left
those branches in, because something may use them in future.
Added one test to the DAX skip list since it's the IDSetQ version
of a StringSetQ test that was already on there, changed skip list
to refer to both tests by name instead of by number.
2023-03-23 14:17:06 -05:00
Vengata Krishnan
9e39eee9c9
fb-2049 improve test coverage for select statement (#2339) 2023-03-23 11:10:57 -04:00
Travis Turner
2f7ae30784
Add HasDirective to dax.Node struct to force Directive on restart (#2335)
For on-prem serverless, if we restart the process containing the
controller and computer(s), when they come back up, the controller
doesn't know that the computers have been restarted, so it doesn't send
them a directive. This change forces the controller to send a directive
upon startup by a computer.
2023-03-21 13:22:16 -05:00
Vengata Krishnan
2cf972b5d1
fb-2036 improve coverage for create view statement (#2333) 2023-03-21 14:06:38 -04:00
Bruce Baranowski
ca99d47249
Add SQL3 tests - /planner/inbuiltfunctionsstring.go (#2331)
* scalar string function test expansion
2023-03-20 17:04:27 -04:00
Vengata Krishnan
693ea1c3a0
fb-2056 improve test coverage for alter table statement. (#2332) 2023-03-20 13:02:37 -04:00
Vengata Krishnan
72871e6e5d
FB-2054 - improve create table timestamp column type coverage (#2330) 2023-03-20 13:01:23 -04:00
Vengata Krishnan
2c3be9d1e8
Fix failing selects on views defined with date literals (#2313)
* Fix failing selects on views defined with date literals
* System variables implementation.
2023-03-17 12:24:00 -04:00
Lory Cloutier
b729348c02
Add SQL3 test for oppqlgroupby.go (#2326)
FB-2027
The DataTypeIDSet and default branches in groupByColumns weren't getting tested.
Added tests to make sure they are now covered.
2023-03-16 14:58:19 -05:00
tgruben
7ae2f0225b
add test coverage for ordring by string, bools, and timestamps (#2327) 2023-03-16 14:51:57 -05:00
tgruben
c9c63b22b4
Add SQL3 Tests added bulk insert tests (#2324)
* added bulk insert tests

* test idset,stringset,bool in parquet

* bulk insert time coverage
2023-03-16 13:02:39 -05:00
David Kagan
c10762220a
renamed 2 system tables (#2310)
* renamed 2 system tables

* adding table column for types

* added a type field to fb_database_nodes system table

* updated ClusterNode struct

* adding backwards compatibility

this commit also adds support for ordering systemTables and implements the method

* fixed linting

---------

Co-authored-by: Travis Turner <travis@molecula.com>
2023-03-15 17:43:11 -05:00
tgruben
f514474014
Test Row Append (#2323) 2023-03-15 13:13:44 -05:00
tgruben
e02ea2c2e7
SQL3 tests newMessageError and all the constructors (#2320)
* sql3 wire protocol message constructor tests

* convert to testify assertion, clarify comment
2023-03-15 12:41:35 -05:00
Travis Turner
aa17b8d725
Enable linter: stylecheck (#2317)
* Enable linter: stylecheck

This enabled the stylecheck linter, but excludes some staticchecks for
now. The following are ignored because they will take a bit of time to
address, but the intention is to address them and remove them from the
exclusion list.

ST1000: at least one file in a package should have a package comment
ST1003: golang naming standards
ST1008: error should be returned as the last argument
ST1016: methods on the same type should have the same receiver name
ST1020: comment on exported function

* Address ST1015

For some reason this failed in CI but not locally. I can't figure out
why that check isn't happening locally. This just moves the switch
statements around so that the `default` is the first (or last) item.

* Adjust error string in test to match case-adjusted error

* Remove TestCloseTimeout
2023-03-14 08:45:18 -05:00
Jacob Brinlee
cd32cd7696
handle empty avg agg (#2316)
* handle empty avg agg
2023-03-13 12:59:38 -05:00
Travis Turner
c79cc3b7db
linter: prealloc (#2315) 2023-03-11 21:19:05 -06:00
Travis Turner
d2856bfeee
Linters! (#2314)
* Add (commented out) linters that we should introduce

I went through the available linters and added (commented out) the ones
I think we should work on in the near term. In other words, fix them,
then uncomment them so they are enabled in CI.

* linter: errchkjson

* linter: ineffassign

* linter: gosimple

* linter: errname
2023-03-10 15:13:15 -06:00
Lory Cloutier
6de130fe39
Added date_trunc time/date scalar function (#2312)
FB-1961
Added function and test coverage.
2023-03-10 14:49:47 -06:00
rachithrr
ef14f3a560
FB-1894: Implement DateTimeDiff() (#2307) 2023-03-10 10:12:27 -06:00
Lory Cloutier
b17582110f
Change datepart function to datetimepart (#2303)
FB-1897
The specs for the datetimepart function are, as far as i can tell,
identical to the existing datepart function. Per Pat, replaced the
datepart function with datetimepart rather than just adding
datetimepart as an alias. Made sure existing tests that were using
datepart got switched over.
Second go at this after sorting out weirdness with git.
2023-03-09 13:04:38 -06:00
Vengata Krishnan
4d484641f2
Gracefully handle divide by zero (#2306)
Divide by zero in SQL expressions will be reported as SQL errors.
2023-03-08 16:51:28 -05:00
rachithrr
909c62d44e
FB-1895: Implement DateTimeFromParts (#2296) 2023-03-07 16:47:07 -06:00
tgruben
dc6cbad3fc
compileOrderingTermExpr needs to return alias and not expression (#2300) 2023-03-07 15:56:58 -06:00
Lory Cloutier
7ea4135ecf
Add datetimename function to SQL3 (#2293)
FB-1896
Added the datetimename function, which returns parts of a timestamp
as strings. Month and day of the week are named ("January", "Monday")
while others are returned as a string of digits ("2023").
Added tests to the test definitions.
2023-03-07 12:58:44 -06:00
Vengata Krishnan
0708673df5
fb-1893 Adding new scalar SQL function datetimeAdd(timeunit, duration, target) (#2295)
* fb-1893 Adding new scalar SQL function datetimeAdd(timeunit, duration, target)
2023-03-07 11:16:00 -05:00
tgruben
dba15669c6
fb-1915 Support large id's in NDJSON (#2290)
* uses json.Decoder to allow for large integer values in ndjson format in bulk import
2023-03-03 15:37:56 -06:00
tgruben
cbbaba98cd
Use json.Number decoder to handle large ints in sql wire protocol (#2285)
* Use json.Number decoder to handle large ints in sql wireprotocol
2023-03-02 14:49:55 -06:00
Pat Okeeffe
9386fc75b2
implement select from time quantum columns (fb-1654) (#2282)
* first time quantum queries working

* implement select from timequantum columns

* skip a dax test

* make linter happy

* addressed review feedback

* reverted over eager test elimination
2023-03-02 00:06:58 -06:00
seebs
b35c240da7
handle count(*) in having correctly (#2274)
* correct reference for `having count(*)`

It turns out that `having count(*) ...` was always treating
the count(*) as exactly 1. After studying this a lot, I noticed
that in fact, we correctly handle other counts. The reason is
that there's already code to recognize aggregates in `having`
clauses as matching aggregates that are being computed -- but
it only covers the other aggregate clause types, not the newly
added `countStarPlanExpression` from making `count(*)` work even
if there's no `_id` field.

We add several corresponding test cases.

* fix sum(a_decimal) type conversion

Added a test case for this, and also added a fix for it.
Underlying issue: qualifiedRefPlanExpression could end up
producing an int64 instead of a pql.Decimal, even though it
had expected type Decimal.

Originally this worked by politely converting an int64 to
a pql.Decimal in the Evaluate phase, but this was not ideal;
the real question is why it was coming out as an int64 at
that step. Showed this to Pat, who spent a while studying it
and produced a better fix.

* temporarily comment out test which fails in DAX
2023-03-01 23:49:45 -06:00
seebs
b7e9879526
forward-port tests from SQL1 tree (#2261)
This forward-ports a number of tests from the previous SQL
implementation. The porting is approximate in a number of ways,
and not all tests are implemented/tested yet.

In particular, several tests are currently disabled because
we don't support `limit n` constructs.

The tests that were primarily tests of the parser have been
brought forward as parser tests. One of them has been altered
to add parentheses, because our parser interprets
	fld1 between 1 and 3 and fld2 = 2
as:
	fld1 between (1 and 3) and (fld2 = 2)
which is invalid, while the old parser apparently interpreted it
as:
	(fld1 between 1 and 3) and (fld2 = 2)

We have not yet verified the SQL spec's requirements here, but
sqlite agrees with our old parser, not our new parser, so this
may be a regression.

The old tests expected an INNER JOIN to suppress duplicate
values. Our new code does not, which is consistent with other
SQL implementations. This is a change, but the old behavior
appears to have been wrong. (You can still suppress duplicate
values by specifying DISTINCT.)

In the previous implementations, a value like `count(*)` had
`count(*)` as its column name. In the new implementation,
it has an empty string as its column name.

Related to this, the prior implementation allowed you to
write
	select age, count(*) from grouper group by age having count > 1
but the new implementationt requires that to be spelled as
	having count(*) > 1

This is consistent with other SQL implementations, so I think
the new behavior is correct.

The behavior of SHOW COLUMNS and SHOW TABLES has changed, in
that the specific results returned are significantly different.
Perhaps more significantly, the old system spelled the former
query as SHOW FIELDS, rather than SHOW COLUMNS. This may be
considered a regression, in that `SHOW FIELDS` no longer works,
and we should consider whether any hypothetical users might
have been relying on the output of either of these. (I hope
not, the new output is much better.)

Some of the old tests (the ones in handler_test) were accommodated
by adding a couple of specific test cases to existing tests,
specifically:
	* handling timestamp values with `Z` rather than `+00:00`
	* a join with a WHERE clause referring to fields in both
	  source tables

We introduce a new "partial" comparison type, because there's
no way for a test of `SHOW TABLES` to contain a correct table
row, because `SHOW TABLES` includes timestamps from when tables
were created. I'm not sure this is the right way to do this.

We add corresponding changes to dax_test, because the DAX tree
tests against the SQL tests.

We change the returned types of field names and field types to
plain strings, ironically because DAX needs this -- the test code
in the DAX tree is getting them back as plain strings, rather
than as dax.FieldName and dax.BaseType.

The tests using `having` are commented out because they don't
seem to be working, a ticket has been filed for this.

Two of the tests that should return strings are instead returning
untranslated integer IDs, but only for DAX, not for the regular
SQL tests, and the `delete` test has been commented out for
DAX-specific errors. If we merge this, the next step is to
ticket those and address them separately.
2023-03-01 13:40:50 -06:00
David Kagan
f8e21b2798
SQL tests now that CodedErrors are across HTTP (#2284)
* 3 todos in delete_database

* forgot to remove some test options
2023-03-01 13:51:14 -05:00
Vengata Krishnan
6777e3dc07
FB-1968 timestamp data type related fixes and enhancements (#2256)
* Removed support for EPOCH column constraint from TIMESTAMP SQL data type.
* Implicit conversion of integers to timestamp will treat the integer value as seconds since unix epoch.
* Add new ToTimeStamp(num, timeunit) SQL scalar function to help convert integer values to timestamp.
2023-02-24 14:57:17 -05:00
Pat Okeeffe
e755fecf63
ORDER BY ....what now!? (fb-1954) (#2257)
* can now order by columns not in the select list

* added testing coverage
2023-02-17 13:35:36 -06:00
Pat Okeeffe
c749e07d03
add support for time quantum inserts with explicit timestamps (fb-1558) (#2262)
* added support for time quantum inserts with explicit timestamps

* fixed copy pasta
2023-02-17 12:06:46 -06:00
Pat Okeeffe
74885c9718
make count(*) not depend on _id (#2258) 2023-02-17 08:46:25 -06:00
Pat Okeeffe
41b8505d70
Aggregation Nation (fb-1955, fb-1887) (#2252)
* make nodeid come from the correct table

* refactored aggregates; added ability to aggregate on expressions not just references

* addressed feedback

* now with the compiler errors fixed after rebase
2023-02-16 10:56:27 -06:00
Seebs
10b60f5d51 set default epoch for timestamps in system tables
If we don't set an epoch, we get a cryptic message on the console.
Note, this message isn't logged properly, it doesn't use the
logger, it uses the `log` package.

	2023/02/09 11:07:23 ERROR: converting timestamp options for
	end_time: checking overflow: custom epoch too far from
	Unix epoch: 0001-01-01 00:00:00 +0000 UTC

Because this uses the log package, it doesn't go to the same place
as other messages, making it a pain to debug.

The underlying problem is that a timestamp can't just have a zero
value for its epoch. So, we set a default epoch of 0 Unix Time.

We should possibly revisit the question of whether the conversion
in the top-level schema.go should handle an epoch which IsZero,
but I'm not sure what "base" should be in that case. In practice,
all existing usages except this one are specifying time.Unix(0, 0)
already.
2023-02-15 14:34:51 -06:00
Seebs
f4e1e63dd0 fix typo in file name 2023-02-15 14:34:51 -06:00
Seebs
5dffbccdff add test coverage, fix bugs caught by added test coverage
Note: We now skip a test because we can't pass it but fixing
it is presently beyond my understanding. In parser_test.go,
we skip
	SELECT * FROM X INNER JOIN Y ON true INNER JOIN Z ON false
because if we stringify it, we put the "ON true" in the wrong
place, and end up with something we can't parse.

The main change here is modifying AssertParseStatement and
AssertStatementStringer (and the corresponding Expression
functions) to also verify that they can clone and round-trip,
and that we can walk expressions. This gives us a ton
more coverage of Clone and conversions to string, and caught
a number of subtle typos and missing type switch cases.

Some of the changes are mostly cosmetic, such as only
including optional words when stringifying expressions
or statements if those optional words were present originally,
as shown by the Pos value stored for those words.

We also drop a lot of trailing apostrophes from some of the
parse test cases, which appear to be harmless but won't be
reproduced when converting back to strings.

We also add a number of additional test cases, or add
clauses to existing test cases, to improve coverage of a
lot of error testing. For instance, we added a decimal
field to the tests of show table, and added cases
using KEYPARTITIONS. (Although it doesn't *do* anything.)

Similarly, whenever we create a statement, we check
the behavior of requesting a list of sources from it, to
verify that source finding code at least runs.
2023-02-15 14:34:51 -06:00
Pat Okeeffe
f205459003
fixed issue with interplay between count(*) and _id column (#2250) 2023-02-14 18:40:15 -06:00
Bruce Baranowski
5c6361918a
FB-1862: Implement Str() scalar string function (#2215)
* Implement STR()
2023-02-14 15:58:36 -05:00