use of com.bakdata.conquery.models.query.resultinfo.UniqueNamer in project conquery by bakdata.
the class DefaultColumnNameTest method checkCombinations.
@ParameterizedTest
@MethodSource("provideCombinations")
void checkCombinations(TestConcept concept, boolean hasCQConceptLabel, String expectedColumnName) {
doAnswer(invocation -> {
final ConceptId id = invocation.getArgument(0);
if (!concept.getId().equals(id)) {
throw new IllegalStateException("Expected the id " + concept.getId() + " but got " + id);
}
return concept;
}).when(DATASET_REGISTRY).resolve(any());
final CQConcept cqConcept = concept.createCQConcept(hasCQConceptLabel);
final UniqueNamer uniqNamer = new UniqueNamer(SETTINGS);
SelectResultInfo info = new SelectResultInfo(concept.extractSelect(cqConcept), cqConcept);
assertThat(uniqNamer.getUniqueName(info)).isEqualTo(expectedColumnName);
}
use of com.bakdata.conquery.models.query.resultinfo.UniqueNamer in project conquery by bakdata.
the class UniqueNameTest method testNameCollision.
@Test
void testNameCollision() {
final UniqueNamer uniqueNamer = new UniqueNamer(new PrintSettings(true, Locale.ROOT, null, new ConqueryConfig(), null));
final SimpleResultInfo info1 = new SimpleResultInfo("test", null);
final SimpleResultInfo info2 = new SimpleResultInfo("test", null);
final SimpleResultInfo info3 = new SimpleResultInfo("test_1", null);
final SimpleResultInfo info4 = new SimpleResultInfo("test", null);
assertThat(uniqueNamer.getUniqueName(info1)).isEqualTo("test");
assertThat(uniqueNamer.getUniqueName(info2)).isEqualTo("test_1");
assertThat(uniqueNamer.getUniqueName(info3)).isEqualTo("test_1_1");
assertThat(uniqueNamer.getUniqueName(info4)).isEqualTo("test_2");
}
use of com.bakdata.conquery.models.query.resultinfo.UniqueNamer in project conquery by bakdata.
the class ManagedQuery method generateColumnDescriptions.
/**
* Generates a description of each column that will appear in the resulting csv.
*/
public List<ColumnDescriptor> generateColumnDescriptions(DatasetRegistry datasetRegistry) {
Preconditions.checkArgument(isInitialized(), "The execution must have been initialized first");
List<ColumnDescriptor> columnDescriptions = new ArrayList<>();
final Locale locale = I18n.LOCALE.get();
PrintSettings settings = new PrintSettings(true, locale, datasetRegistry, config, null);
UniqueNamer uniqNamer = new UniqueNamer(settings);
// First add the id columns to the descriptor list. The are the first columns
for (ResultInfo header : config.getFrontend().getQueryUpload().getIdResultInfos()) {
columnDescriptions.add(ColumnDescriptor.builder().label(uniqNamer.getUniqueName(header)).type(ResultType.IdT.INSTANCE.typeInfo()).build());
}
final UniqueNamer collector = new UniqueNamer(settings);
getResultInfos().forEach(info -> columnDescriptions.add(info.asColumnDescriptor(settings, collector)));
return columnDescriptions;
}
use of com.bakdata.conquery.models.query.resultinfo.UniqueNamer in project conquery by bakdata.
the class CsvRenderer method toCSV.
public void toCSV(List<ResultInfo> idHeaders, List<ResultInfo> infos, Stream<EntityResult> resultStream) {
UniqueNamer uniqNamer = new UniqueNamer(cfg);
final String[] headers = Stream.concat(idHeaders.stream(), infos.stream()).map(uniqNamer::getUniqueName).toArray(String[]::new);
writer.writeHeaders(headers);
createCSVBody(cfg, infos, resultStream);
}
use of com.bakdata.conquery.models.query.resultinfo.UniqueNamer in project conquery by bakdata.
the class ExcelRenderer method writeHeader.
/**
* Write the header and initialize the columns for the table environment.
* Also autosize the columns according to the header width.
*/
private void writeHeader(SXSSFSheet sheet, List<ResultInfo> idHeaders, List<ResultInfo> infos, XSSFTable table) {
CTTableColumns columns = table.getCTTable().addNewTableColumns();
columns.setCount(idHeaders.size() + infos.size());
UniqueNamer uniqueNamer = new UniqueNamer(cfg);
{
Row header = sheet.createRow(0);
// First to create the columns and track them for auto size before the first row is written
int currentColumn = 0;
for (ResultInfo idHeader : idHeaders) {
CTTableColumn column = columns.addNewTableColumn();
// Table column ids MUST be set and MUST start at 1, excel will fail otherwise
column.setId(currentColumn + 1);
final String uniqueName = uniqueNamer.getUniqueName(idHeader);
column.setName(uniqueName);
Cell headerCell = header.createCell(currentColumn);
headerCell.setCellValue(uniqueName);
// Track column explicitly, because sheet.trackAllColumnsForAutoSizing() does not work with
// sheet.getTrackedColumnsForAutoSizing(), if no flush has happened
sheet.trackColumnForAutoSizing(currentColumn);
currentColumn++;
}
for (ResultInfo info : infos) {
final String columnName = uniqueNamer.getUniqueName(info);
CTTableColumn column = columns.addNewTableColumn();
column.setId(currentColumn + 1);
column.setName(columnName);
Cell headerCell = header.createCell(currentColumn);
headerCell.setCellValue(columnName);
sheet.trackColumnForAutoSizing(currentColumn);
currentColumn++;
}
}
}
Aggregations