-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUIDEM-80] Query recorder #85
base: main
Are you sure you want to change the base?
Conversation
Add a component that can record queries to Quidem files and play them back. Here is an example: // Step 1. A recorder in RECORD mode creates "foo.iq". ConnectionFactory postgres; Config config = Config.empty() .withFile("foo.iq") .withMode(RECORD) .withConnectionFactory(postgres); Recorder recorder = Recorder.create(config); recorder.executeQuery("select count(*) from emp", "empCount", result -> { assertThat(result.getMetaData().getColumnCount(), is(1)); assertThat(result.next(), is(true)); assertThat(result.getInt(1), is(13)); }); recorder.close(); // Step 2. A recorder in PLAY mode reads "foo.iq" created by step 1. Config config2 = Config.empty() .withFile("foo.iq") .withMode(PLAY); Recorder recorder2 = Recorder.create(config); recorder.executeQuery("select count(*) from emp", "empCount", result -> { assertThat(result.getMetaData().getColumnCount(), is(1)); assertThat(result.next(), is(true)); assertThat(result.getInt(1), is(13)); }); recorder2.close(); Here is the `foo.iq` file that is generated in step 1 and read in step 2: !use "postgres" # empCount select count(*) as c from emp; c:int ====== 13 !ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The might be some useful testing scenarios where we want to disambiguate between null and empty string.
return wasNull; | ||
} | ||
|
||
@Override public String getString(int columnIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a way to represent an empty string different from null might be useful. Thinking of scenarios where we test grouping sets across edge cases, e.g. empty str, null in same query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point. I believe the encoding allows us to store both nulls and empty strings, but it's trickier with strings than with data types such as DATE and INTEGER. I will add a test. The following Postgres query seems pretty good:
# with t as (select "ENAME",
# substring("ENAME", 1, mod("MGR",5) - 1) as s
# from emp)
# select s, s is null, char_length(s) from t;
ENAME | s | ?column? | char_length
--------+-----+----------+-------------
SMITH | S | f | 1
ALLEN | AL | f | 2
WARD | WA | f | 2
JONES | JON | f | 3
MARTIN | MA | f | 2
BLAKE | BLA | f | 3
CLARK | CLA | f | 3
SCOTT | | f | 0
KING | | t |
TURNER | TU | f | 2
ADAMS | AD | f | 2
JAMES | JA | f | 2
FORD | | f | 0
MILLER | M | f | 1
(14 rows)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 7b1a50f should fix this.
…r single-quotes We still cannot encode strings that contain line endings.
Fixes #80