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

Table read sparse data #1633

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ public DocumentSource documentSource(Row row) {
}
try {
final Object columnValue = row.getObject(i);
// We have a choice here: convert into JSON null (explicit) or drop (save space)?
// For now, do former: may change or make configurable later.
if (columnValue == null) {
result.putNull(columnName);
} else {
// By default, null value will not be returned.
// https://github.com/stargate/data-api/issues/1636 issue for adding nullOption
if (columnValue != null) {
result.put(columnName, codec.toJSON(objectMapper, columnValue));
}
} catch (ToJSONCodecException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
package io.stargate.sgv2.jsonapi.api.v1.tables;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.stargate.sgv2.jsonapi.api.v1.AbstractKeyspaceIntegrationTestBase;

/** Abstract class for all table int tests that needs a collection to execute tests in. */
public class AbstractTableIntegrationTestBase extends AbstractKeyspaceIntegrationTestBase {
private static final ObjectMapper MAPPER = new ObjectMapper();

String removeNullValues(String doc) {
ObjectNode newNode = MAPPER.createObjectNode();
JsonNode oldNode = null;
try {
oldNode = MAPPER.readTree(doc);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Failed to parse JSON: " + doc, e);
}
oldNode
.fields()
.forEachRemaining(
entry -> {
JsonNode value = entry.getValue();
if (!value.isNull()) {
newNode.putIfAbsent(entry.getKey(), value);
}
});
return newNode.toString();
}

// protected DataApiResponseValidator createTableWithColumns(
// String tableName, Map<String, Object> columns, Object primaryKeyDef) {
// return createTable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ public void findOneSingleStringKey() {
.wasSuccessful()
.hasJSONField(
"data.document",
"""
// By default, null values are not returned
removeNullValues(
"""
{
"id": "c",
"age": null,
"name": null
}
""");
"""));
}

@Test
Expand Down Expand Up @@ -255,7 +257,7 @@ public void findOneDocIdKey() {
}
""")
.wasSuccessful()
.hasJSONField("data.document", DOC_B_JSON);
.hasJSONField("data.document", removeNullValues(DOC_B_JSON));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void unsetSuccessful() {
.updateOne(FULL_PRIMARY_KEY_FILTER_DEFAULT_ROW, updateClauseJSON)
.wasSuccessful()
.hasNoWarnings();
checkUpdatedData(FULL_PRIMARY_KEY_FILTER_DEFAULT_ROW, expectedUpdatedRow);
checkUpdatedData(FULL_PRIMARY_KEY_FILTER_DEFAULT_ROW, removeNullValues(expectedUpdatedRow));
}

@Test
Expand Down