Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

julianhyde
Copy link
Collaborator

@julianhyde julianhyde commented Dec 19, 2024

Fixes #80

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
@julianhyde julianhyde changed the title Query recorder (#80) [MOREL-80] Query recorder Dec 19, 2024
@julianhyde julianhyde changed the title [MOREL-80] Query recorder [QUIDEM-80] Query recorder Dec 19, 2024
Copy link

@jswett77 jswett77 left a 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) {

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.

Copy link
Collaborator Author

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)

Copy link
Collaborator Author

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query recorder
2 participants