use of org.folio.dbschema.Index in project raml-module-builder by folio-org.
the class IndexTest method sqlsetMultiFieldNamesWrapSetCaseSensitive.
@Test
void sqlsetMultiFieldNamesWrapSetCaseSensitive() {
Index idx = index("testIdx", "testIdx");
idx.setCaseSensitive(true);
idx.setRemoveAccents(false);
idx.setMultiFieldNames("test1,test2.test3");
assertEquals("concat_space_sql(test_table.jsonb->>'test1' , test_table.jsonb->'test2'->>'test3')", idx.getFinalSqlExpression("test_table"));
}
use of org.folio.dbschema.Index in project raml-module-builder by folio-org.
the class IndexTest method index.
/**
* @return Index with fieldName, fieldPath, caseSensitive=true and removeAccents=false
*/
private Index index(String fieldName, String fieldPath) {
Index index = new Index();
index.setFieldName(fieldName);
index.setFieldPath(fieldPath);
index.setCaseSensitive(true);
index.setRemoveAccents(false);
return index;
}
use of org.folio.dbschema.Index in project raml-module-builder by folio-org.
the class IndexTest method sqlExpression.
@Test
void sqlExpression() {
Index idx = index("testIdx", "testIdx");
idx.setSqlExpression("concat_space_sql()");
assertEquals("concat_space_sql()", idx.getFinalSqlExpression("test_table"));
}
use of org.folio.dbschema.Index in project raml-module-builder by folio-org.
the class IndexTest method sqlsetMultiFieldNamesWrapSetCaseSensitiveSetRemoveAccents.
@Test
void sqlsetMultiFieldNamesWrapSetCaseSensitiveSetRemoveAccents() {
Index idx = index("testIdx", "testIdx");
idx.setCaseSensitive(true);
idx.setRemoveAccents(true);
idx.setMultiFieldNames("test1,test2.test3");
assertEquals("f_unaccent(concat_space_sql(test_table.jsonb->>'test1' , test_table.jsonb->'test2'->>'test3'))", idx.getFinalSqlExpression("test_table"));
}
use of org.folio.dbschema.Index in project raml-module-builder by folio-org.
the class CQL2PgJSON method indexNode.
private String indexNode(String index, Table targetTable, CQLTermNode node, IndexTextAndJsonValues vals, CqlModifiers modifiers) throws QueryValidationException {
// primary key
if ("id".equals(index)) {
return pgId(node, index);
}
DbIndex dbIndex;
if (targetTable == null || dbTable.equals(targetTable)) {
dbIndex = dbIndexMap.computeIfAbsent(index, i -> DbSchemaUtils.getDbIndex(dbTable, index));
} else {
// foreign table
dbIndex = dbIndexMap.computeIfAbsent(vals.getIndexJson(), i -> DbSchemaUtils.getDbIndex(targetTable, index));
}
if (dbIndex.isForeignKey()) {
return pgId(node, index);
}
String comparator = node.getRelation().getBase().toLowerCase();
switch(comparator) {
case "=":
if (CqlTermFormat.NUMBER == modifiers.getCqlTermFormat()) {
return queryBySql(dbIndex, vals, node, comparator, modifiers);
} else {
return queryByFt(index, dbIndex, vals, node, comparator, modifiers, targetTable);
}
case "adj":
case "all":
case "any":
return queryByFt(index, dbIndex, vals, node, comparator, modifiers, targetTable);
case "==":
case "<>":
if (CqlTermFormat.STRING == modifiers.getCqlTermFormat()) {
return queryByLike(index, dbIndex, vals, node, comparator, modifiers, targetTable);
} else {
return queryBySql(dbIndex, vals, node, comparator, modifiers);
}
case "<":
case ">":
case "<=":
case ">=":
return queryBySql(dbIndex, vals, node, comparator, modifiers);
default:
throw new CQLFeatureUnsupportedException("Relation " + comparator + " not implemented yet: " + node.toString());
}
}
Aggregations