Skip to content

Conversation

jnmt
Copy link
Collaborator

@jnmt jnmt commented Aug 25, 2025

Description

This PR adds integration tests for the table store.

Related issues and/or PRs

Depends on:

Changes made

  • Add integration tests for the table store.

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

Release notes

Added integration tests for the table store.

@jnmt jnmt self-assigned this Aug 25, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @jnmt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a comprehensive suite of integration tests for the table store functionality. It establishes a new common-test module to centralize shared test utilities and configurations, and then leverages this setup to validate various SQL-like operations (SELECT, INSERT, UPDATE, metadata queries, history queries) against the table store. Additionally, it includes minor refinements to the Scan contract to improve handling of primary and index key conditions.

Highlights

  • New common-test Module: A dedicated Gradle module (common-test) has been introduced to centralize shared test utilities and configurations, promoting reusability across different components.
  • Extensive Table Store Integration Tests: A new TableStoreEndToEndTest class has been added, providing thorough integration tests for the table store's SQL-like capabilities, covering data manipulation (INSERT, UPDATE, SELECT), metadata queries, and historical data retrieval.
  • Refined Scan Contract Logic: The Scan contract in generic-contracts has been updated to improve the validation logic for primary and index key conditions, specifically handling IS NULL and IS NOT NULL operators more robustly.
  • Gradle Build Configuration Updates: The build configurations for client, table-store, and settings.gradle have been updated to incorporate the new common-test module and to define a dedicated integrationTest source set and task for the table store.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive suite of integration tests for the table store, which is a valuable addition for ensuring its stability and correctness. The refactoring to create a common-test module for shared test utilities is also a good move towards better code organization. While the overall changes are positive, I've identified a few areas for improvement. Specifically, I've commented on a fragile path construction in the test base class, a brittle method for generating PartiQL query strings that should be refactored for robustness, and some misleading test method names that could cause confusion. Addressing these points will enhance the quality and maintainability of the new test suite.

Comment on lines +197 to +216
private String toPartiQLJsonString(JsonNode node) {
String result = jacksonSerDe.serialize(node);

// Remove double quotation in the key
result = FIELD_KEY.matcher(result).replaceAll("$1:");

// Convert string value to '...'
result = STRING_VALUE.matcher(result).replaceAll("'$1'");

// Escape single quotation
Matcher m = SINGLE_QUOTE_ESCAPE.matcher(result);
StringBuffer sb = new StringBuffer();
while (m.find()) {
String inner = m.group(1).replace("'", "''");
m.appendReplacement(sb, "'" + inner + "'");
}
m.appendTail(sb);

return sb.toString();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The implementation of toPartiQLJsonString is very fragile because it uses regular expressions to manipulate a serialized JSON string. This approach can easily fail with more complex JSON structures, such as nested objects or strings containing special characters (e.g., ") that are escaped by the JSON serializer.

A more robust approach is to build the PartiQL string by recursively traversing the JsonNode object. This avoids the pitfalls of string manipulation and correctly handles all valid JSON structures. Here is a suggested refactoring that achieves this:

  private String toPartiQLJsonString(JsonNode node) {
    if (node.isObject()) {
      return "{" + java.util.stream.StreamSupport.stream(java.util.Spliterators.spliteratorUnknownSize(node.fields(), java.util.Spliterator.ORDERED), false)
          .map(e -> e.getKey() + ":" + toPartiQLJsonString(e.getValue()))
          .collect(java.util.stream.Collectors.joining(",")) + "}";
    } else if (node.isArray()) {
      return "[" + java.util.stream.StreamSupport.stream(java.util.Spliterators.spliteratorUnknownSize(node.elements(), java.util.Spliterator.ORDERED), false)
          .map(this::toPartiQLJsonString)
          .collect(java.util.stream.Collectors.joining(",")) + "]";
    } else if (node.isTextual()) {
      return "'" + node.asText().replace("'", "''") + "'";
    } else {
      return node.toString();
    }
  }

Copy link
Collaborator Author

@jnmt jnmt Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. We will introduce a new feature/grammar that can handle native JSON without this kind of conversion in #246. So, let's keep as is for now.

StorageFactory factory = StorageFactory.create(props);
storage = factory.getStorage();
storageAdmin = factory.getStorageAdmin();
ledgerSchemaPath = Paths.get(System.getProperty("user.dir") + LEDGER_SCHEMA_PATH);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The way ledgerSchemaPath is constructed is brittle. It relies on user.dir pointing to a specific directory relative to the schema file, which might not always be the case depending on how the tests are executed (e.g., from an IDE with a different working directory). This can lead to FileNotFoundException and flaky tests.

A more robust approach would be to place the schema file in the test resources and load it using the class loader. This would make the test setup independent of the execution environment.

For example, if ledger-schema.json is in src/main/resources of the common-test module, you could load it like this:

URL schemaUrl = getClass().getResource("/ledger-schema.json");
if (schemaUrl == null) {
    throw new IllegalStateException("Could not find ledger-schema.json");
}
ledgerSchemaPath = Paths.get(schemaUrl.toURI());

Copy link
Collaborator Author

@jnmt jnmt Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better for some cases, but we only use it in the tests in this repo, and it's a symlink shared in the schema-loader directory. So, I prefer to leave it as is.

@jnmt jnmt changed the base branch from master to fix-null-condition-handling August 25, 2025 05:22
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive integration tests for the table store module, providing end-to-end testing capabilities for SQL statement execution and validation operations.

  • Adds a new TableStoreEndToEndTest class with extensive test coverage for SELECT, INSERT, UPDATE, and metadata operations
  • Configures integration test infrastructure including Gradle build configuration and CI/CD pipeline setup
  • Creates a base test class LedgerEndToEndTestBase for common ledger testing functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
table-store/src/integration-test/java/com/scalar/dl/tablestore/TableStoreEndToEndTest.java Comprehensive integration test suite covering SQL operations, joins, history queries, and validation
table-store/build.gradle Gradle configuration for integration test source set and task definition
common-test/src/main/java/com/scalar/dl/ledger/LedgerEndToEndTestBase.java Base class providing common ledger test infrastructure and server setup
common-test/scripts/ledger-schema.json Symlink to ledger schema for test configuration
common-test/build.gradle Additional dependencies for ledger testing support
.github/workflows/scalar.yml CI workflow configuration for running table store integration tests

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jnmt jnmt mentioned this pull request Aug 26, 2025
7 tasks
Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looking good! Thank you!
Left one question. PTAL!

@jnmt jnmt requested a review from feeblefakie August 28, 2025 04:15
Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants