-
Notifications
You must be signed in to change notification settings - Fork 11
FlatPostgresCollection Create Doc Impl #266
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
Changes from all commits
00e9a9c
31846e9
2fdbf0e
1727dd0
a62fbc2
6b7595b
7b4ef2a
598cb25
9c173b9
7bf77c5
6d03cd5
c3f5f7e
827381f
602037b
c8a53eb
31f16e2
c139bee
75150e3
5412f9b
bf5ca5c
57b623a
233c9c4
9f8811e
bfd6651
70ec4b3
6d1c277
910ef8c
3e2c178
9061e24
c3024b0
900c87f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,51 @@ | ||
| package org.hypertrace.core.documentstore; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import lombok.Getter; | ||
|
|
||
| /* | ||
| * Represent the result object for CREATE operation of document store APIs. | ||
| * */ | ||
| @Getter | ||
| public class CreateResult { | ||
| private boolean succeed; | ||
|
|
||
| public CreateResult(boolean succeed) { | ||
| this.succeed = succeed; | ||
| private final CreateStatus status; | ||
| private final boolean onRetry; | ||
| private final List<String> skippedFields; | ||
|
|
||
| public CreateResult(CreateStatus status, boolean onRetry, List<String> skippedFields) { | ||
| this.status = status; | ||
| this.onRetry = onRetry; | ||
| this.skippedFields = skippedFields != null ? skippedFields : Collections.emptyList(); | ||
| } | ||
|
|
||
| public CreateResult(boolean isSuccess) { | ||
| this(isSuccess ? CreateStatus.SUCCESS : CreateStatus.FAILED, false, Collections.emptyList()); | ||
| } | ||
|
|
||
| public CreateResult(boolean isSucceed, boolean onRetry, List<String> skippedFields) { | ||
| this(determineStatus(isSucceed, skippedFields), onRetry, skippedFields); | ||
| } | ||
|
|
||
| private static CreateStatus determineStatus(boolean isSucceed, List<String> skippedFields) { | ||
| if (!isSucceed) { | ||
| return CreateStatus.FAILED; | ||
| } | ||
| return (skippedFields != null && !skippedFields.isEmpty()) | ||
| ? CreateStatus.PARTIAL | ||
| : CreateStatus.SUCCESS; | ||
| } | ||
|
|
||
| public boolean isSucceed() { | ||
| return succeed; | ||
| return status == CreateStatus.SUCCESS || status == CreateStatus.PARTIAL; | ||
| } | ||
|
|
||
| public boolean isPartial() { | ||
| return status == CreateStatus.PARTIAL; | ||
| } | ||
|
|
||
| public boolean isDocumentIgnored() { | ||
| return status == CreateStatus.IGNORED; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.hypertrace.core.documentstore; | ||
|
|
||
| /** Status of a document create operation. */ | ||
| public enum CreateStatus { | ||
| /** Document created successfully with all fields. */ | ||
| SUCCESS, | ||
|
|
||
| /** Document created but some fields were skipped (didn't match schema). */ | ||
| PARTIAL, | ||
|
|
||
| /** Document was intentionally not created due to IGNORE_DOCUMENT strategy. */ | ||
| IGNORED, | ||
|
|
||
| /** Operation failed (no valid columns found or other error). */ | ||
| FAILED | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package org.hypertrace.core.documentstore.model.exception; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Exception thrown when a document field doesn't match the expected schema. This can occur when: | ||
| * | ||
| * <ul> | ||
| * <li>A field in the document doesn't exist in the schema | ||
| * <li>A field's value type doesn't match the expected schema type | ||
| * </ul> | ||
| */ | ||
| public class SchemaMismatchException extends IOException { | ||
|
|
||
| public SchemaMismatchException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public SchemaMismatchException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.hypertrace.core.documentstore.model.options; | ||
|
|
||
| /** | ||
| * Strategy for handling document fields that don't match the schema during write operations. This | ||
| * is mostly applicable to flat collections as they conform to a schema | ||
| * | ||
| * <p>This enum defines how the system should behave when encountering fields that either don't | ||
| * exist in the schema or have incompatible types. | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also mention what is the default (in case not specified)? Or, is it a mandatory field?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default can go in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even better would be to expose a static method called |
||
| public enum MissingColumnStrategy { | ||
| /** | ||
| * Skip unmatched fields and continue with the write operation. The document will be written with | ||
| * only the fields that match the schema. | ||
| */ | ||
| SKIP, | ||
|
|
||
| /** | ||
| * Throw a {@link org.hypertrace.core.documentstore.model.exception.SchemaMismatchException} when | ||
| * a field doesn't match the schema. The write operation will fail. | ||
| */ | ||
| THROW, | ||
| IGNORE_DOCUMENT | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can also come in later when the need arises. |
||
| } | ||
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.
Nit: Can be a set.