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

Fix #1417: optimize/improve codec lookup handling #1443

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

tatu-at-datastax
Copy link
Contributor

@tatu-at-datastax tatu-at-datastax commented Sep 20, 2024

What this PR does:

Changes linear-scan lookup into map-based lookup (one- or two-phase depending on direction). Also improves error messages for partial misses where we support CQL type but not particular coercion (like Boolean from Integer) to indicate it's Java value mismatch and not (fully) unsupported type.

Which issue(s) this PR fixes:
Fixes #1417

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

@tatu-at-datastax tatu-at-datastax changed the title (WIP) Fix #1417: optimize/improve codec lookup handling Fix #1417: optimize/improve codec lookup handling Sep 21, 2024
@tatu-at-datastax tatu-at-datastax marked this pull request as ready for review September 21, 2024 02:18
@tatu-at-datastax tatu-at-datastax requested a review from a team as a code owner September 21, 2024 02:18
Copy link
Contributor

@Yuqi-Du Yuqi-Du left a comment

Choose a reason for hiding this comment

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

LGTM

@tatu-at-datastax tatu-at-datastax merged commit 77e4965 into main Sep 23, 2024
3 checks passed
@tatu-at-datastax tatu-at-datastax deleted the tatu/1417-codec-lookup-improvement branch September 23, 2024 16:57
Copy link
Contributor

@amorton amorton left a comment

Choose a reason for hiding this comment

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

nit picks and some things

}
}

public static JSONCodecRegistry create(List<JSONCodec<?, ?>> codecs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this static factory seems unnecessary, it has one line that calls the constructor

this.codecs = Objects.requireNonNull(codecs, "codecs must not be null");
private JSONCodecRegistry(List<JSONCodec<?, ?>> codecs) {
Objects.requireNonNull(codecs, "codecs must not be null");
this.codecsByCQLType = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unnecessary use of this

if (match == null) {
// Different exception for this case: CQL type supported but not from given Java type
// (f.ex, CQL Boolean from Java/JSON number)
throw new ToCQLCodecException(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an important change, the code to verify a document for inserting may need to change

@@ -49,21 +61,35 @@ public class JSONCodecRegistry {
*/
public <JavaT, CqlT> JSONCodec<JavaT, CqlT> codecToCQL(
TableMetadata table, CqlIdentifier column, Object value)
throws UnknownColumnException, MissingJSONCodecException {
throws UnknownColumnException, MissingJSONCodecException, ToCQLCodecException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the doc comments list all the errors

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.

Optimize JSONCodecRegistry to-CQL codec lookup: linear search won't scale
3 participants