Search in sources :

Example 1 with ResultType

use of com.bakdata.conquery.models.externalservice.ResultType in project conquery by bakdata.

the class ArrowUtil method listField.

private static Field listField(ResultInfo info, @NonNull String uniqueName) {
    if (!(info.getType() instanceof ResultType.ListT)) {
        throw new IllegalStateException("Expected result type of " + ResultType.ListT.class.getName() + " but got " + info.getType().getClass().getName());
    }
    final ResultType elementType = ((ResultType.ListT) info.getType()).getElementType();
    BiFunction<ResultInfo, String, Field> nestedFieldCreator = FIELD_MAP.getOrDefault(elementType.getClass(), ArrowUtil::stringField);
    final Field nestedField = nestedFieldCreator.apply(info, uniqueName);
    return new Field(uniqueName, FieldType.nullable(ArrowType.List.INSTANCE), List.of(nestedField));
}
Also used : Field(org.apache.arrow.vector.types.pojo.Field) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo)

Example 2 with ResultType

use of com.bakdata.conquery.models.externalservice.ResultType in project conquery by bakdata.

the class CsvResultGenerationTest method generateExpectedCSV.

private String generateExpectedCSV(List<EntityResult> results, List<ResultInfo> resultInfos, PrintSettings settings) {
    List<String> expected = new ArrayList<>();
    expected.add(ResultTestUtil.ID_FIELDS.stream().map(info -> info.defaultColumnName(settings)).collect(Collectors.joining(",")) + "," + getResultTypes().stream().map(ResultType::typeInfo).collect(Collectors.joining(",")) + "\n");
    results.stream().map(EntityResult.class::cast).forEach(res -> {
        for (Object[] line : res.listResultLines()) {
            StringJoiner valueJoiner = new StringJoiner(",");
            valueJoiner.add(String.valueOf(res.getEntityId()));
            valueJoiner.add(String.valueOf(res.getEntityId()));
            for (int lIdx = 0; lIdx < line.length; lIdx++) {
                Object val = line[lIdx];
                if (val == null) {
                    valueJoiner.add("");
                    continue;
                }
                ResultInfo info = resultInfos.get(lIdx);
                final String printVal = info.getType().printNullable(settings, val);
                valueJoiner.add(printVal.contains(String.valueOf(CONFIG.getCsv().getDelimeter())) ? "\"" + printVal + "\"" : printVal);
            }
            expected.add(valueJoiner + "\n");
        }
    });
    return expected.stream().collect(Collectors.joining());
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) ArrayList(java.util.ArrayList) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) EntityPrintId(com.bakdata.conquery.models.identifiable.mapping.EntityPrintId) Locale(java.util.Locale) I18n(com.bakdata.conquery.models.i18n.I18n) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) ResultTestUtil.getTestEntityResults(com.bakdata.conquery.io.result.ResultTestUtil.getTestEntityResults) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ResultTestUtil(com.bakdata.conquery.io.result.ResultTestUtil) StringJoiner(java.util.StringJoiner) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) NotNull(org.jetbrains.annotations.NotNull) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) ArrayList(java.util.ArrayList) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) StringJoiner(java.util.StringJoiner)

Example 3 with ResultType

use of com.bakdata.conquery.models.externalservice.ResultType in project conquery by bakdata.

the class ArrowResultGenerationTest method getPrintValue.

private static String getPrintValue(Object obj, ResultType type, PrintSettings settings) {
    if (obj == null) {
        return "null";
    }
    if (type.equals(ResultType.DateRangeT.INSTANCE)) {
        // Special case for daterange in this test because it uses a StructVector, we rebuild the structural information
        List<?> dr = (List<?>) obj;
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        final int min = (int) dr.get(0);
        final int max = (int) dr.get(1);
        // Handle cases where one of the limits is infinity
        if (!CDate.isNegativeInfinity(min)) {
            sb.append("\"min\":").append(min);
        }
        if (!CDate.isNegativeInfinity(min) && !CDate.isPositiveInfinity(max)) {
            sb.append(",");
        }
        if (!CDate.isPositiveInfinity(max)) {
            sb.append("\"max\":").append(max);
        }
        sb.append("}");
        return sb.toString();
    }
    if (type.equals(ResultType.ResolutionT.INSTANCE)) {
        return type.printNullable(settings, obj);
    }
    if (obj instanceof Collection) {
        Collection<?> col = (Collection<?>) obj;
        // Workaround: Arrow deserializes lists as a JsonStringArrayList which has a JSON String method
        new StringJoiner(",", "[", "]");
        @NonNull ResultType elemType = ((ResultType.ListT) type).getElementType();
        return col.stream().map(v -> getPrintValue(v, elemType, settings)).collect(Collectors.joining(", ", "[", "]"));
    }
    return obj.toString();
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) ArrayList(java.util.ArrayList) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) EntityPrintId(com.bakdata.conquery.models.identifiable.mapping.EntityPrintId) ByteArrayInputStream(java.io.ByteArrayInputStream) FloatingPointPrecision(org.apache.arrow.vector.types.FloatingPointPrecision) ArrowRenderer(com.bakdata.conquery.io.result.arrow.ArrowRenderer) CDate(com.bakdata.conquery.models.common.CDate) Locale(java.util.Locale) I18n(com.bakdata.conquery.models.i18n.I18n) ArrowStreamReader(org.apache.arrow.vector.ipc.ArrowStreamReader) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) DictionaryProvider(org.apache.arrow.vector.dictionary.DictionaryProvider) UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) FieldVector(org.apache.arrow.vector.FieldVector) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) NonNull(lombok.NonNull) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) FieldType(org.apache.arrow.vector.types.pojo.FieldType) Collection(java.util.Collection) IOException(java.io.IOException) Field(org.apache.arrow.vector.types.pojo.Field) Collectors(java.util.stream.Collectors) ArrowStreamWriter(org.apache.arrow.vector.ipc.ArrowStreamWriter) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ResultTestUtil(com.bakdata.conquery.io.result.ResultTestUtil) StringJoiner(java.util.StringJoiner) ROOT_ALLOCATOR(com.bakdata.conquery.io.result.arrow.ArrowUtil.ROOT_ALLOCATOR) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) DateUnit(org.apache.arrow.vector.types.DateUnit) InputStream(java.io.InputStream) NonNull(lombok.NonNull) Collection(java.util.Collection) ArrayList(java.util.ArrayList) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) List(java.util.List) ResultType(com.bakdata.conquery.models.externalservice.ResultType) StringJoiner(java.util.StringJoiner)

Aggregations

ResultType (com.bakdata.conquery.models.externalservice.ResultType)3 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)3 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)2 ResultTestUtil (com.bakdata.conquery.io.result.ResultTestUtil)2 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)2 I18n (com.bakdata.conquery.models.i18n.I18n)2 EntityPrintId (com.bakdata.conquery.models.identifiable.mapping.EntityPrintId)2 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)2 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)2 SelectResultInfo (com.bakdata.conquery.models.query.resultinfo.SelectResultInfo)2 EntityResult (com.bakdata.conquery.models.query.results.EntityResult)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Locale (java.util.Locale)2 StringJoiner (java.util.StringJoiner)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Field (org.apache.arrow.vector.types.pojo.Field)2