Search in sources :

Example 1 with UniqueNamer

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);
}
Also used : UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) ConceptId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptId) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with UniqueNamer

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");
}
Also used : SimpleResultInfo(com.bakdata.conquery.models.query.resultinfo.SimpleResultInfo) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) Test(org.junit.jupiter.api.Test)

Example 3 with UniqueNamer

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;
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo)

Example 4 with UniqueNamer

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);
}
Also used : UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer)

Example 5 with UniqueNamer

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++;
        }
    }
}
Also used : CTTableColumns(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns) UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) Row(org.apache.poi.ss.usermodel.Row) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) CTTableColumn(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

UniqueNamer (com.bakdata.conquery.models.query.resultinfo.UniqueNamer)7 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)2 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)1 ConceptId (com.bakdata.conquery.models.identifiable.ids.specific.ConceptId)1 SelectResultInfo (com.bakdata.conquery.models.query.resultinfo.SelectResultInfo)1 SimpleResultInfo (com.bakdata.conquery.models.query.resultinfo.SimpleResultInfo)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)1 ArrowWriter (org.apache.arrow.vector.ipc.ArrowWriter)1 Field (org.apache.arrow.vector.types.pojo.Field)1 Schema (org.apache.arrow.vector.types.pojo.Schema)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 CTTableColumn (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn)1 CTTableColumns (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns)1