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));
}
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;
}
}
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;
}
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);
}
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())));
}
}
Aggregations