use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class FilterTest method parseQuery.
private Query parseQuery(StandaloneSupport support) throws JSONException, IOException {
rawFilterValue.put("filter", support.getDataset().getName() + ".concept.connector.filter");
FilterValue<?> result = parseSubTree(support, rawFilterValue, Jackson.MAPPER.getTypeFactory().constructType(FilterValue.class));
CQTable cqTable = new CQTable();
cqTable.setFilters(Collections.singletonList(result));
cqTable.setConnector(connector);
CQConcept cqConcept = new CQConcept();
cqTable.setConcept(cqConcept);
cqConcept.setElements(Collections.singletonList(concept));
cqConcept.setTables(Collections.singletonList(cqTable));
if (dateRange != null) {
CQDateRestriction restriction = new CQDateRestriction();
restriction.setDateRange(dateRange);
restriction.setChild(cqConcept);
return new ConceptQuery(restriction);
}
return new ConceptQuery(cqConcept);
}
use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class ManagedQuery method makeDefaultLabel.
/**
* Creates a default label based on the submitted {@link QueryDescription}.
* The Label is customized by mentioning that a description contained a
* {@link CQExternal}, {@link CQReusedQuery} or {@link CQConcept}, in this order.
* In case of one ore more {@link CQConcept} the distinct labels of the concepts are chosen
* and concatinated until a length of {@value #MAX_CONCEPT_LABEL_CONCAT_LENGTH} is reached.
* All further labels are dropped.
*/
@Override
protected String makeDefaultLabel(PrintSettings cfg) {
final StringBuilder sb = new StringBuilder();
final Map<Class<? extends Visitable>, List<Visitable>> sortedContents = Visitable.stream(query).collect(Collectors.groupingBy(Visitable::getClass));
int sbStartSize = sb.length();
// Check for CQExternal
List<Visitable> externals = sortedContents.getOrDefault(CQExternal.class, Collections.emptyList());
if (!externals.isEmpty()) {
if (sb.length() > 0) {
sb.append(" ");
}
sb.append(C10N.get(CQElementC10n.class, I18n.LOCALE.get()).external());
}
// Check for CQReused
if (sortedContents.containsKey(CQReusedQuery.class)) {
if (sb.length() > 0) {
sb.append(" ");
}
sb.append(C10N.get(CQElementC10n.class, I18n.LOCALE.get()).reused());
}
// Check for CQConcept
if (sortedContents.containsKey(CQConcept.class)) {
if (sb.length() > 0) {
sb.append(" ");
}
// Track length of text we are appending for concepts.
final AtomicInteger length = new AtomicInteger();
sortedContents.get(CQConcept.class).stream().map(CQConcept.class::cast).map(c -> makeLabelWithRootAndChild(c, cfg)).filter(Predicate.not(Strings::isNullOrEmpty)).distinct().takeWhile(elem -> length.addAndGet(elem.length()) < MAX_CONCEPT_LABEL_CONCAT_LENGTH).forEach(label -> sb.append(label).append(" "));
// Last entry will output one Space that we don't want
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
// If not all Concept could be included in the name, point that out
if (length.get() > MAX_CONCEPT_LABEL_CONCAT_LENGTH) {
sb.append(" ").append(C10N.get(CQElementC10n.class, I18n.LOCALE.get()).furtherConcepts());
}
}
// Fallback to id if nothing could be extracted from the query description
if (sbStartSize == sb.length()) {
sb.append(getId().getExecution());
}
return sb.toString();
}
use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class ArrowResultGenerationTest method generateFieldsValue.
@Test
void generateFieldsValue() {
List<ResultInfo> resultInfos = getResultTypes().stream().map(ResultTestUtil.TypedSelectDummy::new).map(select -> new SelectResultInfo(select, new CQConcept())).collect(Collectors.toList());
List<Field> fields = generateFields(resultInfos, // Custom column namer so we don't require a dataset registry
UNIQUE_NAMER);
assertThat(fields).containsExactlyElementsOf(List.of(new Field("BOOLEAN", FieldType.nullable(ArrowType.Bool.INSTANCE), null), new Field("INTEGER", FieldType.nullable(new ArrowType.Int(32, true)), null), new Field("NUMERIC", FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), null), new Field("CATEGORICAL", FieldType.nullable(new ArrowType.Utf8()), null), new Field("RESOLUTION", FieldType.nullable(new ArrowType.Utf8()), null), new Field("DATE", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null), new Field("DATE_RANGE", FieldType.nullable(ArrowType.Struct.INSTANCE), List.of(new Field("min", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null), new Field("max", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null))), new Field("STRING", FieldType.nullable(new ArrowType.Utf8()), null), new Field("MONEY", FieldType.nullable(new ArrowType.Int(32, true)), null), new Field("LIST[BOOLEAN]", FieldType.nullable(ArrowType.List.INSTANCE), List.of(new Field("LIST[BOOLEAN]", FieldType.nullable(ArrowType.Bool.INSTANCE), null))), new Field("LIST[DATE_RANGE]", FieldType.nullable(ArrowType.List.INSTANCE), List.of(new Field("LIST[DATE_RANGE]", FieldType.nullable(ArrowType.Struct.INSTANCE), List.of(new Field("min", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null), new Field("max", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null))))), new Field("LIST[STRING]", FieldType.nullable(ArrowType.List.INSTANCE), List.of(new Field("LIST[STRING]", FieldType.nullable(new ArrowType.Utf8()), null)))));
}
use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class SerializationTests method formConfig.
@Test
public void formConfig() throws JSONException, IOException {
final CentralRegistry registry = new CentralRegistry();
final Dataset dataset = new Dataset("test-dataset");
registry.register(dataset);
ExportForm form = new ExportForm();
AbsoluteMode mode = new AbsoluteMode();
form.setTimeMode(mode);
mode.setForm(form);
mode.setFeatures(List.of(new CQConcept()));
ObjectMapper mapper = FormConfigProcessor.getMAPPER();
JsonNode values = mapper.valueToTree(form);
FormConfig formConfig = new FormConfig(form.getClass().getAnnotation(CPSType.class).id(), values);
formConfig.setDataset(dataset);
SerializationTestUtil.forType(FormConfig.class).registry(registry).test(formConfig);
}
use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class SerializationTests method testFormQuery.
@Test
public void testFormQuery() throws IOException, JSONException {
CQConcept concept = new CQConcept();
final TreeConcept testConcept = new TreeConcept();
Dataset dataset = new Dataset();
dataset.setName("testDataset");
testConcept.setDataset(dataset);
testConcept.setName("concept");
final ConceptTreeConnector connector = new ConceptTreeConnector();
connector.setConcept(testConcept);
connector.setName("connector1");
testConcept.setConnectors(List.of(connector));
concept.setElements(Collections.singletonList(testConcept));
CQTable[] tables = { new CQTable() };
connector.setTable(new Table());
tables[0].setConnector(connector);
tables[0].setConcept(concept);
concept.setTables(Arrays.asList(tables));
ConceptQuery subQuery = new ConceptQuery(concept);
CQOr features = new CQOr();
features.setChildren(Collections.singletonList(concept));
AbsoluteFormQuery query = new AbsoluteFormQuery(subQuery, CDateRange.exactly(LocalDate.now()).toSimpleRange(), ArrayConceptQuery.createFromFeatures(Collections.singletonList(features)), List.of(ExportForm.ResolutionAndAlignment.of(Resolution.COMPLETE, Alignment.NO_ALIGN), ExportForm.ResolutionAndAlignment.of(Resolution.QUARTERS, Alignment.QUARTER)));
CentralRegistry centralRegistry = new CentralRegistry();
centralRegistry.register(dataset);
centralRegistry.register(testConcept);
centralRegistry.register(connector);
SerializationTestUtil.forType(AbsoluteFormQuery.class).registry(centralRegistry).test(query);
}
Aggregations