|
|
|
@ -270,9 +270,10 @@ public class EntityKeyMapping { |
|
|
|
Collectors.joining(", ")); |
|
|
|
} |
|
|
|
|
|
|
|
public static String buildLatestJoins(QueryContext ctx, EntityFilter entityFilter, EntityType entityType, List<EntityKeyMapping> latestMappings) { |
|
|
|
return latestMappings.stream().map(mapping -> mapping.toLatestJoin(ctx, entityFilter, entityType)).collect( |
|
|
|
Collectors.joining(" ")); |
|
|
|
public static String buildLatestJoins(QueryContext ctx, EntityFilter entityFilter, EntityType entityType, List<EntityKeyMapping> latestMappings, boolean countQuery) { |
|
|
|
return latestMappings.stream().filter(mapping -> !countQuery || mapping.hasFilter()) |
|
|
|
.map(mapping -> mapping.toLatestJoin(ctx, entityFilter, entityType)).collect( |
|
|
|
Collectors.joining(" ")); |
|
|
|
} |
|
|
|
|
|
|
|
public static String buildQuery(QueryContext ctx, List<EntityKeyMapping> mappings, EntityFilterType filterType) { |
|
|
|
@ -363,19 +364,14 @@ public class EntityKeyMapping { |
|
|
|
} |
|
|
|
|
|
|
|
private String buildAttributeSelection() { |
|
|
|
String attrValAlias = getValueAlias(); |
|
|
|
String attrTsAlias = getTsAlias(); |
|
|
|
String attrValSelection = |
|
|
|
String.format("(coalesce(cast(%s.bool_v as varchar), '') || " + |
|
|
|
"coalesce(%s.str_v, '') || " + |
|
|
|
"coalesce(cast(%s.long_v as varchar), '') || " + |
|
|
|
"coalesce(cast(%s.dbl_v as varchar), '') || " + |
|
|
|
"coalesce(cast(%s.json_v as varchar), '')) as %s", alias, alias, alias, alias, alias, attrValAlias); |
|
|
|
String attrTsSelection = String.format("%s.last_update_ts as %s", alias, attrTsAlias); |
|
|
|
return String.join(", ", attrValSelection, attrTsSelection); |
|
|
|
return buildTimeSeriesOrAttrSelection(true); |
|
|
|
} |
|
|
|
|
|
|
|
private String buildTimeSeriesSelection() { |
|
|
|
return buildTimeSeriesOrAttrSelection(false); |
|
|
|
} |
|
|
|
|
|
|
|
private String buildTimeSeriesOrAttrSelection(boolean attr) { |
|
|
|
String attrValAlias = getValueAlias(); |
|
|
|
String attrTsAlias = getTsAlias(); |
|
|
|
String attrValSelection = |
|
|
|
@ -384,8 +380,25 @@ public class EntityKeyMapping { |
|
|
|
"coalesce(cast(%s.long_v as varchar), '') || " + |
|
|
|
"coalesce(cast(%s.dbl_v as varchar), '') || " + |
|
|
|
"coalesce(cast(%s.json_v as varchar), '')) as %s", alias, alias, alias, alias, alias, attrValAlias); |
|
|
|
String attrTsSelection = String.format("%s.ts as %s", alias, attrTsAlias); |
|
|
|
return String.join(", ", attrValSelection, attrTsSelection); |
|
|
|
String attrTsSelection = String.format("%s.%s as %s", alias, attr ? "last_update_ts" : "ts", attrTsAlias); |
|
|
|
if (this.isSortOrder) { |
|
|
|
String attrNumAlias = getSortOrderNumAlias(); |
|
|
|
String attrVarcharAlias = getSortOrderStrAlias(); |
|
|
|
String attrSortOrderSelection = |
|
|
|
String.format("coalesce(%s.dbl_v, cast(%s.long_v as double precision), (case when %s.bool_v then 1 else 0 end)) %s," + |
|
|
|
"coalesce(%s.str_v, cast(%s.json_v as varchar), '') %s", alias, alias, alias, attrNumAlias, alias, alias, attrVarcharAlias); |
|
|
|
return String.join(", ", attrValSelection, attrTsSelection, attrSortOrderSelection); |
|
|
|
} else { |
|
|
|
return String.join(", ", attrValSelection, attrTsSelection); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String getSortOrderStrAlias() { |
|
|
|
return getValueAlias() + "_so_varchar"; |
|
|
|
} |
|
|
|
|
|
|
|
public String getSortOrderNumAlias() { |
|
|
|
return getValueAlias() + "_so_num"; |
|
|
|
} |
|
|
|
|
|
|
|
private String buildKeyQuery(QueryContext ctx, String alias, KeyFilter keyFilter, |
|
|
|
@ -425,11 +438,11 @@ public class EntityKeyMapping { |
|
|
|
if (predicate.getType().equals(FilterPredicateType.NUMERIC)) { |
|
|
|
return this.buildNumericPredicateQuery(ctx, field, (NumericFilterPredicate) predicate); |
|
|
|
} else if (predicate.getType().equals(FilterPredicateType.STRING)) { |
|
|
|
if (key.getKey().equals("entityType") && !filterType.equals(EntityFilterType.RELATIONS_QUERY)){ |
|
|
|
if (key.getKey().equals("entityType") && !filterType.equals(EntityFilterType.RELATIONS_QUERY)) { |
|
|
|
field = ctx.getEntityType().toString(); |
|
|
|
return this.buildStringPredicateQuery(ctx, field, (StringFilterPredicate) predicate) |
|
|
|
.replace("lower(" + field, "lower('" + field + "'") |
|
|
|
.replace(field + " ","'" + field + "' "); |
|
|
|
.replace(field + " ", "'" + field + "' "); |
|
|
|
} else { |
|
|
|
return this.buildStringPredicateQuery(ctx, field, (StringFilterPredicate) predicate); |
|
|
|
} |
|
|
|
@ -481,13 +494,13 @@ public class EntityKeyMapping { |
|
|
|
stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '%%')", operationField, paramName, operationField, paramName); |
|
|
|
break; |
|
|
|
case CONTAINS: |
|
|
|
if (value.length()>0) { |
|
|
|
if (value.length() > 0) { |
|
|
|
value = "%" + value + "%"; |
|
|
|
} |
|
|
|
stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName); |
|
|
|
break; |
|
|
|
case NOT_CONTAINS: |
|
|
|
if (value.length()>0) { |
|
|
|
if (value.length() > 0) { |
|
|
|
value = "%" + value + "%"; |
|
|
|
} |
|
|
|
stringOperationQuery = String.format("%s not like :%s) or (%s is null and :%s != '')", operationField, paramName, operationField, paramName); |
|
|
|
|