Search in sources :

Example 36 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project molgenis-emx2 by molgenis.

the class EvaluateExpressionsTest method testCheckValidationSuccess.

@Test
public void testCheckValidationSuccess() {
    Map<String, Object> values = new HashMap<>();
    Collection<Column> columns = new ArrayList<>();
    String validation = "true && true";
    Column column = new Column("name");
    column.setValidation(validation);
    columns.add(column);
    checkValidation(values, columns);
}
Also used : HashMap(java.util.HashMap) Column(org.molgenis.emx2.Column) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 37 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project molgenis-emx2 by molgenis.

the class EvaluateExpressionsTest method testCheckValidationInvalidExpression.

@Test
public void testCheckValidationInvalidExpression() {
    Map<String, Object> values = new HashMap<>();
    Collection<Column> columns = new ArrayList<>();
    String validation = "this is very invalid";
    Column column = new Column("name");
    column.setValidation(validation);
    columns.add(column);
    try {
        checkValidation(values, columns);
    } catch (MolgenisException exception) {
        assertEquals("Cannot execute expression: this is very invalid", exception.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) Column(org.molgenis.emx2.Column) ArrayList(java.util.ArrayList) MolgenisException(org.molgenis.emx2.MolgenisException) Test(org.junit.Test)

Example 38 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project molgenis-emx2 by molgenis.

the class SqlColumnRefArrayExecutor method createReferenceExistsCheck.

/**
 * trigger on this column to check if foreign key exists. Might be composite key, i.e., list of
 * columns
 */
private static void createReferenceExistsCheck(DSLContext jooq, Column column) {
    String schemaName = column.getSchema().getName();
    Name thisTable = name(schemaName, column.getTable().getTableName());
    Name toTable = name(column.getRefSchema(), column.getRefTableName());
    String functionName = getReferenceExistsCheckName(column);
    List<Reference> references = column.getReferences();
    String fromColumns = references.stream().map(r -> name(r.getName()).toString()).collect(Collectors.joining(","));
    String toColumns = references.stream().map(r -> name(r.getRefTo()).toString()).collect(Collectors.joining(","));
    String errorColumns = references.stream().map(r -> "COALESCE(error_row." + name(r.getRefTo()).toString() + ",'NULL')").collect(Collectors.joining("||','||"));
    String exceptFilter = references.stream().map(r -> {
        if (r.isOverlappingRef()) {
            return name(r.getRefTo()) + " = NEW." + name(r.getName());
        } else {
            return name(r.getRefTo()) + " = ANY (NEW." + name(r.getName()) + ")";
        }
    }).collect(Collectors.joining(" AND "));
    String unnestRefs = references.stream().map(r -> {
        // can be overlapping with non_array reference
        if (r.isOverlappingRef()) {
            return "NEW." + name(r.getName()) + " AS " + name(r.getRefTo());
        } else {
            return "UNNEST(NEW." + name(r.getName()) + ") AS " + name(r.getRefTo());
        }
    }).collect(Collectors.joining(","));
    String nonRefLinkFieldsAreNotNull = references.stream().filter(r -> !r.isOverlapping()).map(r2 -> "error_row." + name(r2.getRefTo()) + " IS NOT NULL ").collect(Collectors.joining(" OR "));
    jooq.execute("CREATE OR REPLACE FUNCTION {0}() RETURNS trigger AS $BODY$ " + "\nDECLARE error_row RECORD;" + "\nBEGIN" + "\n\tFOR error_row IN SELECT {1} EXCEPT SELECT {2} FROM {3} WHERE {10} LOOP" + // exclude if only refLink fields are set
    "\n\t\tIF {11} THEN" + "\n\t\t\tRAISE EXCEPTION USING ERRCODE='23503', MESSAGE = 'insert or update on table \"'||{9}||'\" violates foreign key (ref_array) constraint'" + " , DETAIL = 'Key ('||{6}||')=('|| {5} ||') is not present in table \"'||{7}||'\", column(s)('||{8}||')';" + "\n\t\tEND IF;" + "\n\tEND LOOP;" + "\n\tRETURN NEW;" + "\nEND; $BODY$ LANGUAGE plpgsql;", // 0
    name(schemaName, functionName), // 1
    keyword(unnestRefs), // 2
    keyword(toColumns), // 3
    toTable, // 4
    thisTable, // 5
    keyword(errorColumns), // 6
    inline(fromColumns), // 7
    inline(column.getRefTableName()), // 8
    inline(toColumns), // 9
    inline(column.getTableName()), // 10
    keyword(exceptFilter), // 11
    keyword(nonRefLinkFieldsAreNotNull));
    // add the trigger
    jooq.execute("CREATE CONSTRAINT TRIGGER {0} " + "\n\tAFTER INSERT OR UPDATE OF {1} ON {2} FROM {3}" + "\n\tDEFERRABLE INITIALLY IMMEDIATE " + "\n\tFOR EACH ROW EXECUTE PROCEDURE {4}()", name(functionName), keyword(fromColumns), thisTable, toTable, name(column.getTable().getSchema().getName(), functionName));
}
Also used : Column(org.molgenis.emx2.Column) SqlColumnExecutor.validateColumn(org.molgenis.emx2.sql.SqlColumnExecutor.validateColumn) List(java.util.List) DSL(org.jooq.impl.DSL) Name(org.jooq.Name) Collection(java.util.Collection) Reference(org.molgenis.emx2.Reference) DSLContext(org.jooq.DSLContext) Collectors(java.util.stream.Collectors) Reference(org.molgenis.emx2.Reference) Name(org.jooq.Name)

Example 39 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project molgenis-emx2 by molgenis.

the class SqlColumnRefExecutor method createRefConstraints.

public static void createRefConstraints(DSLContext jooq, Column refColumn) {
    validateColumn(refColumn);
    Name fkeyConstraintName = name(getRefConstraintName(refColumn));
    Name thisTable = getJooqTable(refColumn.getTable()).getQualifiedName();
    List<Name> thisColumns = refColumn.getReferences().stream().map(c -> name(c.getName())).collect(Collectors.toList());
    List<Name> otherColumns = refColumn.getReferences().stream().map(c -> name(c.getRefTo())).collect(Collectors.toList());
    Name fkeyTable = name(refColumn.getRefTable().getSchemaName(), refColumn.getRefTableName());
    ConstraintForeignKeyOnStep constraint = constraint(fkeyConstraintName).foreignKey(thisColumns.toArray(new Name[thisColumns.size()])).references(fkeyTable, otherColumns.toArray(new Name[otherColumns.size()])).onUpdateCascade();
    if (refColumn.isCascadeDelete()) {
        constraint = constraint.onDeleteCascade();
    }
    jooq.alterTable(getJooqTable(refColumn.getTable())).add(constraint).execute();
    jooq.execute("ALTER TABLE {0} ALTER CONSTRAINT {1} DEFERRABLE INITIALLY IMMEDIATE", thisTable, fkeyConstraintName);
    jooq.createIndex(getIndexName(refColumn)).on(thisTable, thisColumns.toArray(new Name[thisColumns.size()])).execute();
}
Also used : Column(org.molgenis.emx2.Column) SqlColumnExecutor.validateColumn(org.molgenis.emx2.sql.SqlColumnExecutor.validateColumn) DSL.constraint(org.jooq.impl.DSL.constraint) List(java.util.List) DSL.name(org.jooq.impl.DSL.name) SqlTableMetadataExecutor.getJooqTable(org.molgenis.emx2.sql.SqlTableMetadataExecutor.getJooqTable) Name(org.jooq.Name) DSLContext(org.jooq.DSLContext) Collectors(java.util.stream.Collectors) ConstraintForeignKeyOnStep(org.jooq.ConstraintForeignKeyOnStep) ConstraintForeignKeyOnStep(org.jooq.ConstraintForeignKeyOnStep) Name(org.jooq.Name)

Example 40 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project beam by apache.

the class BigtableTableTestUtils method bigTableSegmentedRows.

static com.google.bigtable.v2.Row[] bigTableSegmentedRows() {
    com.google.bigtable.v2.Row[] rows = new com.google.bigtable.v2.Row[5];
    List<Column> columns = ImmutableList.of(column("boolColumn", booleanToByteArray(true)), column("doubleColumn", doubleToByteArray(5.5)), column("longColumn", Longs.toByteArray(10L)), column("stringColumn", "stringValue".getBytes(UTF_8)));
    Family family = Family.newBuilder().setName("familyTest").addAllColumns(columns).build();
    for (int i = 0; i < 5; i++) {
        rows[i] = com.google.bigtable.v2.Row.newBuilder().setKey(byteStringUtf8("key" + i)).addFamilies(family).build();
    }
    return rows;
}
Also used : Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family) Row(org.apache.beam.sdk.values.Row)

Aggregations

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)21 ArrayList (java.util.ArrayList)19 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)16 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)16 HashMap (java.util.HashMap)14 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)13 List (java.util.List)11 Column (org.molgenis.emx2.Column)11 Column (com.google.bigtable.v2.Column)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)9 Family (com.google.bigtable.v2.Family)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)8 Test (org.junit.Test)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named)7