Search in sources :

Example 31 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class ArrowResultGenerationTest method writeAndRead.

@Test
void writeAndRead() throws IOException {
    // Initialize internationalization
    I18n.init();
    // Prepare every input data
    PrintSettings printSettings = new PrintSettings(false, Locale.ROOT, null, CONFIG, (cer) -> EntityPrintId.from(Integer.toString(cer.getEntityId()), Integer.toString(cer.getEntityId())), (selectInfo) -> selectInfo.getSelect().getLabel());
    // The Shard nodes send Object[] but since Jackson is used for deserialization, nested collections are always a list because they are not further specialized
    List<EntityResult> results = getTestEntityResults();
    ManagedQuery mquery = getTestQuery();
    // First we write to the buffer, than we read from it and parse it as TSV
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    renderToStream((root) -> new ArrowStreamWriter(root, new DictionaryProvider.MapDictionaryProvider(), output), printSettings, BATCH_SIZE, ResultTestUtil.ID_FIELDS, mquery.getResultInfos(), mquery.streamResults());
    InputStream inputStream = new ByteArrayInputStream(output.toByteArray());
    String computed = readTSV(inputStream);
    assertThat(computed).isNotBlank();
    assertThat(computed).isEqualTo(generateExpectedTSV(results, mquery.getResultInfos(), printSettings));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) ArrowStreamWriter(org.apache.arrow.vector.ipc.ArrowStreamWriter) Test(org.junit.jupiter.api.Test)

Example 32 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class ManagedForm method addResult.

/**
 * Distribute the result to a sub query.
 */
@Override
public void addResult(@NonNull MetaStorage storage, FormShardResult result) {
    if (result.getError().isPresent()) {
        fail(storage, result.getError().get());
        return;
    }
    ManagedExecutionId subQueryId = result.getSubQueryId();
    ManagedQuery subQuery = flatSubQueries.get(subQueryId);
    subQuery.addResult(storage, result);
    switch(subQuery.getState()) {
        case DONE:
            if (allSubQueriesDone()) {
                finish(storage, ExecutionState.DONE);
            }
            break;
        case FAILED:
            // Fail the whole execution if a subquery fails
            fail(storage, result.getError().orElseThrow(() -> new IllegalStateException(String.format("Query [%s] failed but no error was set.", getId()))));
            break;
        case NEW:
        case RUNNING:
        default:
            break;
    }
}
Also used : ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery)

Example 33 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class StoredQueriesProcessorTest method makeState.

@SneakyThrows
private static ExecutionStatus makeState(ManagedExecutionId id, User owner, User callingUser, ExecutionState state, String typeLabel, SecondaryIdDescriptionId secondaryId) {
    OverviewExecutionStatus status = new OverviewExecutionStatus();
    final ManagedQuery execMock = new ManagedQuery() {

        {
            setDataset(DATASET_0);
            setQueryId(id.getExecution());
        }
    };
    status.setTags(new String[0]);
    status.setLabel(id.getExecution().toString());
    status.setPristineLabel(true);
    status.setCreatedAt(LocalDateTime.MIN.atZone(ZoneId.systemDefault()));
    status.setOwner(owner.getId());
    status.setShared(false);
    status.setOwn(owner.equals(callingUser));
    status.setId(id);
    status.setStatus(state);
    status.setQueryType(typeLabel);
    // This is probably not interesting on the overview (only if there is an filter for the search)
    status.setSecondaryId(secondaryId);
    if (state.equals(DONE)) {
        status.setResultUrls(List.of(ResultExcelResource.getDownloadURL(URI_BUILDER.clone(), execMock), ResultCsvResource.getDownloadURL(URI_BUILDER.clone(), execMock), ResultArrowFileResource.getDownloadURL(URI_BUILDER.clone(), execMock), ResultArrowStreamResource.getDownloadURL(URI_BUILDER.clone(), execMock)));
    }
    return status;
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) OverviewExecutionStatus(com.bakdata.conquery.apiv1.OverviewExecutionStatus) SneakyThrows(lombok.SneakyThrows)

Example 34 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class FormConfigTest method setupTest.

@BeforeEach
public void setupTest() {
    final ManagedQuery managedQuery = new ManagedQuery(null, null, dataset);
    managedQuery.setQueryId(UUID.randomUUID());
    form = new ExportForm();
    AbsoluteMode mode = new AbsoluteMode();
    form.setTimeMode(mode);
    form.setQueryGroupId(managedQuery.getId());
    mode.setForm(form);
    mode.setFeatures(List.of(new CQConcept()));
    user = new User("test", "test", storage);
    storage.addUser(user);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) AbsoluteMode(com.bakdata.conquery.apiv1.forms.export_form.AbsoluteMode) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class DownloadLinkGeneration method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    final MetaStorage storage = conquery.getMetaStorage();
    final User user = new User("testU", "testU", storage);
    final String testJson = In.resource("/tests/query/SIMPLE_TREECONCEPT_QUERY/SIMPLE_TREECONCEPT_Query.test.json").withUTF8().readAll();
    final QueryTest test = (QueryTest) JsonIntegrationTest.readJson(conquery.getDataset(), testJson);
    storage.updateUser(user);
    // Manually import data
    ValidatorHelper.failOnError(log, conquery.getValidator().validate(test));
    test.importRequiredData(conquery);
    // Create execution for download
    ManagedQuery exec = new ManagedQuery(test.getQuery(), user, conquery.getDataset());
    storage.addExecution(exec);
    user.addPermission(DatasetPermission.onInstance(Set.of(Ability.READ), conquery.getDataset().getId()));
    {
        // Try to generate a download link: should not be possible, because the execution isn't run yet
        FullExecutionStatus status = IntegrationUtils.getExecutionStatus(conquery, exec.getId(), user, 200);
        assertThat(status.getResultUrls()).isEmpty();
    }
    {
        // Thinker the state of the execution and try again: still not possible because of missing permissions
        exec.setState(ExecutionState.DONE);
        FullExecutionStatus status = IntegrationUtils.getExecutionStatus(conquery, exec.getId(), user, 200);
        assertThat(status.getResultUrls()).isEmpty();
    }
    {
        // Add permission to download: now it should be possible
        user.addPermission(DatasetPermission.onInstance(Set.of(Ability.DOWNLOAD), conquery.getDataset().getId()));
        FullExecutionStatus status = IntegrationUtils.getExecutionStatus(conquery, exec.getId(), user, 200);
        // This Url is missing the `/api` path part, because we use the standard UriBuilder here
        assertThat(status.getResultUrls()).contains(new URL(String.format("%s/datasets/%s/result/%s.csv", conquery.defaultApiURIBuilder().toString(), conquery.getDataset().getId(), exec.getId())));
    }
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) QueryTest(com.bakdata.conquery.integration.json.QueryTest) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) FullExecutionStatus(com.bakdata.conquery.apiv1.FullExecutionStatus) URL(java.net.URL)

Aggregations

ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)37 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)18 Test (org.junit.jupiter.api.Test)18 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)13 User (com.bakdata.conquery.models.auth.entities.User)12 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)8 Dataset (com.bakdata.conquery.models.datasets.Dataset)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 CsvSource (org.junit.jupiter.params.provider.CsvSource)6 CQAnd (com.bakdata.conquery.apiv1.query.concept.specific.CQAnd)5 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)5 List (java.util.List)5 Slf4j (lombok.extern.slf4j.Slf4j)5 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)4 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)4 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)4 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)3 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)3 I18n (com.bakdata.conquery.models.i18n.I18n)3 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)3