Skip to content

fix: remove jsonb_array and fix jsonb data types such that it can be used in schema design and graphql api #4409

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

Merged
merged 35 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4cd9812
fix: remove jsonb_array type
mswertz Oct 29, 2024
5ba651b
fix: remove jsonb_array type
mswertz Oct 29, 2024
adfd5d1
fix tests
mswertz Oct 29, 2024
fe90ef7
Merge branch 'master' into fix/remove_json_array
mswertz Nov 4, 2024
3238649
Merge branch 'master' of github.com:molgenis/molgenis-emx2 into fix/r…
mswertz Nov 6, 2024
69aa6bd
wip
mswertz Nov 6, 2024
917fdb6
undo|
mswertz Nov 6, 2024
8889644
Merge branch 'master' of github.com:molgenis/molgenis-emx2 into fix/r…
mswertz Nov 6, 2024
02141e3
add jsonb to graphql api
mswertz Nov 6, 2024
41443eb
many fixes for the proper json passing
mswertz Nov 6, 2024
16dcee1
fix test
mswertz Nov 6, 2024
e5bedd1
Merge branch 'master' of github.com:molgenis/molgenis-emx2 into fix/r…
mswertz Nov 7, 2024
8e20cad
add test
mswertz Nov 7, 2024
ea0c91a
Merge branch 'master' into fix/remove_json_array
mswertz Nov 11, 2024
3c1aa07
merged
mswertz Nov 15, 2024
092c9d2
Merge branch 'master' of github.com:molgenis/molgenis-emx2 into fix/r…
mswertz Nov 18, 2024
d5dd710
expand test coverage
mswertz Nov 18, 2024
59b7b78
Merge branch 'master' into fix/remove_json_array
mswertz Nov 18, 2024
fc50cf2
remove unused code
mswertz Nov 18, 2024
8f34bdb
merge
mswertz Nov 19, 2024
5febc75
Merge branch 'master' into fix/remove_json_array
svandenhoek Nov 25, 2024
da8e178
Updated code from #4323 to be compatible with this branch
svandenhoek Nov 25, 2024
3755cbd
updated docs
svandenhoek Nov 25, 2024
2188e18
generalized GraphqlCustomTypes in switch
svandenhoek Nov 25, 2024
8414b94
serialize should only throw a CoercingSerializeException (https://www…
svandenhoek Nov 25, 2024
c7ddff2
Updated toJsonb to include full validation
svandenhoek Nov 25, 2024
dad3e7f
Improved JSON validation (no trailing data, duplicate check)
svandenhoek Nov 25, 2024
e3d1243
auto-formatting
svandenhoek Nov 25, 2024
996dfe1
WIP: front-end validation
svandenhoek Nov 26, 2024
d0833c6
Added tests
svandenhoek Nov 26, 2024
150161c
fixes null giving wrong front-end error message
svandenhoek Nov 26, 2024
70f505f
fixed comments
svandenhoek Nov 26, 2024
d2e2d76
more comment fixes
svandenhoek Nov 26, 2024
ff6cdbf
processed feedback
svandenhoek Nov 26, 2024
83f7eec
formatting
svandenhoek Nov 26, 2024
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 @@ -48,7 +48,6 @@ export default {
DATE_ARRAY: "StringDisplay",
DATETIME: "StringDisplay",
DATETIME_ARRAY: "StringDisplay",
JSONB_ARRAY: "ObjectDisplay",
ONTOLOGY_ARRAY: "OntologyFieldValue",
}[this.metadata.columnType];
},
Expand Down
1 change: 0 additions & 1 deletion apps/catalogue/src/components/detailView/SectionField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export default {
DECIMAL_ARRAY: "SectionArrayValue",
DATE_ARRAY: "SectionArrayValue",
DATETIME_ARRAY: "SectionArrayValue",
JSONB_ARRAY: "SectionArrayValue",
ONTOLOGY_ARRAY: "SectionArrayValue",
REF_ARRAY: "RefArrayFieldValue",
REF: "RefFieldValue",
Expand Down
1 change: 0 additions & 1 deletion apps/metadata-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export type CellValueType =
| "DATETIME_ARRAY"
| "PERIOD"
| "JSONB"
| "JSONB_ARRAY"
| "REF"
| "REF_ARRAY"
| "REFBACK"
Expand Down
1 change: 1 addition & 0 deletions apps/schema/src/columnTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default [
"HYPERLINK_ARRAY",
"INT",
"INT_ARRAY",
"JSONB",
"LONG",
"LONG_ARRAY",
"ONTOLOGY",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ private void createTableField(Column col, GraphQLObjectType.Builder tableBuilder
case DATETIME_ARRAY:
case PERIOD_ARRAY:
case UUID_ARRAY:
case JSONB_ARRAY:
tableBuilder.field(
GraphQLFieldDefinition.newFieldDefinition()
.name(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ private static String getEmx1Type(Column c) {
INT_ARRAY,
DATE_ARRAY,
DATETIME_ARRAY,
JSONB_ARRAY,
DECIMAL_ARRAY:
return "array types unsupported in emx1: " + c.getColumnType();
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ private CoreDatatype.XSD columnTypeToXSD(final ColumnType columnType) {
EMAIL_ARRAY,
HEADING,
JSONB,
JSONB_ARRAY,
STRING,
STRING_ARRAY,
TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,6 @@ private Condition whereCondition(
case DATE_ARRAY -> whereConditionArrayEquals(name, operator, toDateArray(values));
case DATETIME_ARRAY -> whereConditionArrayEquals(name, operator, toDateTimeArray(values));
case PERIOD_ARRAY -> whereConditionArrayEquals(name, operator, toYearToSecondArray(values));
case JSONB_ARRAY -> whereConditionArrayEquals(name, operator, toJsonbArray(values));
case REF -> whereConditionRefEquals(name, operator, values);
default ->
throw new SqlQueryException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public static Object getTypedValue(Column c, Row row) {
case PERIOD -> row.getPeriod(name);
case PERIOD_ARRAY -> row.getPeriodArray(name);
case JSONB -> row.getJsonb(name);
case JSONB_ARRAY -> row.getJsonbArray(name);
default ->
throw new UnsupportedOperationException(
"Unsupported columnType found:" + c.getColumnType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ public void testTextArray() {
});
}

@Test
public void testJSON() {
executeTest(
JSONB_ARRAY,
new String[] {"{\"key\":\"value1\"}", "{\"key\":\"value2\"}", "{\"key\":\"value3\"}"});
}

// @Test
// public void testBool() {
// executeTest(BOOL_ARRAY, new Boolean[] {null, true, false});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ public void testTextRef() {
});
}

@Test
public void testJSONRef() {
executeTest(
ColumnType.JSONB,
new String[] {"{\"key\": \"value1\"}", "{\"key\": \"value2\"}", "{\"key\": \"value3\"}"});
}

private void executeTest(ColumnType columnType, Object[] testValues) {

Schema schema = db.dropCreateSchema("TestRefArray" + columnType.toString().toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public enum ColumnType {

// COMPOSITE
JSONB(org.jooq.JSONB.class),
JSONB_ARRAY(org.jooq.JSONB[].class),

// RELATIONSHIP
REF(Object.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ public JSONB getJsonb(String name) {
return TypeUtils.toJsonb(values.get(name));
}

public JSONB[] getJsonbArray(String name) {
return TypeUtils.toJsonbArray(values.get(name));
}

public Row setString(String name, String value) {
this.values.put(name, value);
return this;
Expand Down Expand Up @@ -344,8 +340,6 @@ public <T> T get(String name, Class<T> type) {
return (T) getStringArray(name);
case "JSONB":
return (T) getJsonb(name);
case "JSONB[]":
return (T) getJsonbArray(name);
case "Integer":
return (T) getInteger(name);
case "Integer[]":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.molgenis.emx2.utils;

import java.io.Serializable;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.sql.Timestamp;
Expand Down Expand Up @@ -260,26 +259,10 @@ public static JSONB toJsonb(Object v) {
return (JSONB) v;
}

public static JSONB[] toJsonbArray(Object v) {
public static JSONB[] toJsonbArray(Object[] values) {
// non standard so not using the generic function
if (v == null) return null; // NOSONAR
if (v instanceof String) {
String value = toString(v);
if (value != null) {
v = List.of(JSONB.valueOf(value));
} else {
return null;
}
}
if (v instanceof String[]) {
v = toStringArray(v);
}
if (v instanceof Serializable[]) v = List.of((Serializable[]) v);
if (v instanceof Object[]) v = List.of((Object[]) v);
if (v instanceof List) {
return ((List<Object>) v).stream().map(TypeUtils::toJsonb).toArray(JSONB[]::new);
}
return (JSONB[]) v;
if (values == null) return null; // NOSONAR
return Arrays.stream(values).map(TypeUtils::toJsonb).toArray(JSONB[]::new);
}

public static String toText(Object v) {
Expand Down Expand Up @@ -320,7 +303,6 @@ public static ColumnType getArrayType(ColumnType columnType) {
case DATE -> ColumnType.DATE_ARRAY;
case DATETIME -> ColumnType.DATETIME_ARRAY;
case PERIOD -> ColumnType.PERIOD_ARRAY;
case JSONB -> ColumnType.JSONB_ARRAY;
default ->
throw new UnsupportedOperationException(
"Unsupported array columnType found:" + columnType);
Expand Down Expand Up @@ -392,7 +374,6 @@ public static DataType toJooqType(ColumnType type) {
case PERIOD_ARRAY ->
SQLDataType.INTERVAL.asConvertedDataType(new PeriodConverter()).getArrayDataType();
case JSONB -> SQLDataType.JSONB;
case JSONB_ARRAY -> SQLDataType.JSONB.getArrayDataType();
default ->
// should never happen
throw new IllegalArgumentException("jooqTypeOf(type) : unsupported type '" + type + "'");
Expand Down Expand Up @@ -422,7 +403,7 @@ public static Object getTypedValue(Object v, ColumnType columnType) {
case PERIOD -> TypeUtils.toPeriod(v);
case PERIOD_ARRAY -> TypeUtils.toPeriodArray(v);
case JSONB -> TypeUtils.toJsonb(v);
case JSONB_ARRAY -> TypeUtils.toJsonbArray(v);

default ->
throw new UnsupportedOperationException(
"Unsupported columnType columnType found:" + columnType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.jooq.JSONB;
import org.junit.jupiter.api.Test;
import org.molgenis.emx2.utils.TypeUtils;

Expand All @@ -22,9 +21,6 @@ public void test() {
executeTest(ColumnType.DATE_ARRAY, new LocalDate[] {LocalDate.now(), LocalDate.now()});
executeTest(
ColumnType.DATETIME_ARRAY, new LocalDateTime[] {LocalDateTime.now(), LocalDateTime.now()});
executeTest(
ColumnType.JSONB_ARRAY,
new JSONB[] {JSONB.valueOf("{name:\"blaat\"}"), JSONB.valueOf("{name2:\"blaat2\"}")});

// test null string is trimmed to null correctly
for (ColumnType type : ColumnType.values()) {
Expand Down