use of com.bakdata.conquery.models.datasets.Column in project conquery by bakdata.
the class TableExportQuery method createResultInfos.
private static List<ResultInfo> createResultInfos(int size, Map<SecondaryIdDescription, Integer> secondaryIdPositions, Map<Column, Integer> positions) {
ResultInfo[] infos = new ResultInfo[size];
infos[0] = ConqueryConstants.DATES_INFO;
for (Map.Entry<SecondaryIdDescription, Integer> e : secondaryIdPositions.entrySet()) {
SecondaryIdDescription desc = e.getKey();
Integer pos = e.getValue();
infos[pos] = new SimpleResultInfo(desc.getLabel(), ResultType.IdT.INSTANCE);
}
for (Map.Entry<Column, Integer> entry : positions.entrySet()) {
// 0 Position is date, already covered
final int position = entry.getValue();
// SecondaryIds are pulled to the front, already covered.
final Column column = entry.getKey();
if (position == 0 || column.getSecondaryId() != null) {
continue;
}
infos[position] = new SimpleResultInfo(column.getTable().getLabel() + " " + column.getLabel(), ResultType.resolveResultType(column.getType()));
}
return List.of(infos);
}
use of com.bakdata.conquery.models.datasets.Column in project conquery by bakdata.
the class PreprocessedHeader method assertMatch.
/**
* Verify that the supplied table matches the preprocessed' data in shape.
*/
public void assertMatch(Table table) {
StringJoiner errors = new StringJoiner("\n");
if (table.getColumns().length != getColumns().length) {
errors.add(String.format("Length=`%d` does not match table Length=`%d`", getColumns().length, table.getColumns().length));
}
final Map<String, MajorTypeId> typesByName = Arrays.stream(getColumns()).collect(Collectors.toMap(PPColumn::getName, PPColumn::getType));
for (int i = 0; i < Math.min(table.getColumns().length, getColumns().length); i++) {
final Column column = table.getColumns()[i];
if (!typesByName.containsKey(column.getName())) {
errors.add(String.format("Column[%s] is missing in Import.", column.getName()));
} else if (!typesByName.get(column.getName()).equals(column.getType())) {
errors.add(String.format("Column[%s] Types do not match %s != %s", column.getName(), typesByName.get(column.getName()), column.getType()));
}
}
if (errors.length() != 0) {
log.error(errors.toString());
throw new IllegalArgumentException(String.format("Headers[%s.%s] do not match Table[%s]. More Info in Logs.", getTable(), getName(), table.getId()));
}
}
use of com.bakdata.conquery.models.datasets.Column in project conquery by bakdata.
the class SerializationTests method treeConcept.
@Test
public void treeConcept() throws IOException, JSONException {
Dataset dataset = new Dataset();
dataset.setName("datasetName");
TreeConcept concept = new TreeConcept();
concept.setDataset(dataset);
concept.setLabel("conceptLabel");
concept.setName("conceptName");
Table table = new Table();
Column column = new Column();
column.setLabel("colLabel");
column.setName("colName");
column.setType(MajorTypeId.STRING);
column.setTable(table);
Column dateColumn = new Column();
dateColumn.setLabel("colLabel2");
dateColumn.setName("colName2");
dateColumn.setType(MajorTypeId.DATE);
dateColumn.setTable(table);
table.setColumns(new Column[] { column, dateColumn });
table.setDataset(dataset);
table.setLabel("tableLabel");
table.setName("tableName");
column.setTable(table);
ConceptTreeConnector connector = new ConceptTreeConnector();
connector.setConcept(concept);
connector.setLabel("connLabel");
connector.setName("connName");
connector.setColumn(column);
concept.setConnectors(List.of(connector));
ValidityDate valDate = new ValidityDate();
valDate.setColumn(dateColumn);
valDate.setConnector(connector);
valDate.setLabel("valLabel");
valDate.setName("valName");
connector.setValidityDates(List.of(valDate));
CentralRegistry registry = new CentralRegistry();
registry.register(dataset);
registry.register(concept);
registry.register(column);
registry.register(dateColumn);
registry.register(table);
registry.register(connector);
registry.register(valDate);
final Validator validator = Validators.newValidator();
concept.setValidator(validator);
SerializationTestUtil.forType(TreeConcept.class).registry(registry).injectables(new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}).test(concept);
}
use of com.bakdata.conquery.models.datasets.Column in project conquery by bakdata.
the class SerializationTests method table.
@Test
public void table() throws JSONException, IOException {
Dataset dataset = new Dataset();
dataset.setName("datasetName");
Table table = new Table();
Column column = new Column();
column.setLabel("colLabel");
column.setName("colName");
column.setType(MajorTypeId.STRING);
column.setTable(table);
table.setColumns(new Column[] { column });
table.setDataset(dataset);
table.setLabel("tableLabel");
table.setName("tableName");
CentralRegistry registry = new CentralRegistry();
registry.register(dataset);
registry.register(table);
registry.register(column);
final Validator validator = Validators.newValidator();
SerializationTestUtil.forType(Table.class).registry(registry).injectables(new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}).test(table);
}
use of com.bakdata.conquery.models.datasets.Column in project conquery by bakdata.
the class AdminDatasetProcessor method deleteSecondaryId.
/**
* Delete SecondaryId if it does not have any dependents.
*/
public synchronized void deleteSecondaryId(@NonNull SecondaryIdDescription secondaryId) {
final Namespace namespace = datasetRegistry.get(secondaryId.getDataset().getId());
// Before we commit this deletion, we check if this SecondaryId still has dependent Columns.
final List<Column> dependents = namespace.getStorage().getTables().stream().map(Table::getColumns).flatMap(Arrays::stream).filter(column -> secondaryId.equals(column.getSecondaryId())).collect(Collectors.toList());
if (!dependents.isEmpty()) {
final Set<TableId> tables = dependents.stream().map(Column::getTable).map(Identifiable::getId).collect(Collectors.toSet());
log.error("SecondaryId[{}] still present on {}", secondaryId, tables);
throw new ForbiddenException(String.format("SecondaryId still has dependencies. %s", tables));
}
log.info("Deleting SecondaryId[{}]", secondaryId);
namespace.getStorage().removeSecondaryId(secondaryId.getId());
namespace.sendToAll(new RemoveSecondaryId(secondaryId));
}
Aggregations