-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Select filter value auto-completion for SQL mode (#3277)
- Loading branch information
Showing
27 changed files
with
350 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/bakdata/conquery/mode/StorageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.bakdata.conquery.mode; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import com.bakdata.conquery.io.storage.NamespaceStorage; | ||
import com.bakdata.conquery.models.datasets.Column; | ||
|
||
public interface StorageHandler { | ||
|
||
Stream<String> lookupColumnValues(NamespaceStorage namespaceStorage, Column column); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/com/bakdata/conquery/mode/cluster/ClusterStorageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.bakdata.conquery.mode.cluster; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import com.bakdata.conquery.io.storage.NamespaceStorage; | ||
import com.bakdata.conquery.mode.StorageHandler; | ||
import com.bakdata.conquery.models.datasets.Column; | ||
import com.bakdata.conquery.models.datasets.ImportColumn; | ||
import com.bakdata.conquery.models.events.stores.root.StringStore; | ||
|
||
public class ClusterStorageHandler implements StorageHandler { | ||
|
||
@Override | ||
public Stream<String> lookupColumnValues(NamespaceStorage namespaceStorage, Column column) { | ||
return namespaceStorage.getAllImports().stream() | ||
.filter(imp -> imp.getTable().equals(column.getTable())) | ||
.flatMap(imp -> { | ||
final ImportColumn importColumn = imp.getColumns()[column.getPosition()]; | ||
return ((StringStore) importColumn.getTypeDescription()).iterateValues(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
backend/src/main/java/com/bakdata/conquery/mode/local/SqlStorageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.bakdata.conquery.mode.local; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import com.bakdata.conquery.io.storage.NamespaceStorage; | ||
import com.bakdata.conquery.mode.StorageHandler; | ||
import com.bakdata.conquery.models.datasets.Column; | ||
import com.bakdata.conquery.sql.execution.SqlExecutionService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jooq.DSLContext; | ||
import org.jooq.Record1; | ||
import org.jooq.Select; | ||
import org.jooq.impl.DSL; | ||
|
||
@Slf4j | ||
public class SqlStorageHandler implements StorageHandler { | ||
|
||
private final SqlExecutionService sqlExecutionService; | ||
private final DSLContext dslContext; | ||
|
||
public SqlStorageHandler(SqlExecutionService sqlExecutionService) { | ||
this.sqlExecutionService = sqlExecutionService; | ||
this.dslContext = sqlExecutionService.getDslContext(); | ||
} | ||
|
||
@Override | ||
public Stream<String> lookupColumnValues(NamespaceStorage namespaceStorage, Column column) { | ||
Select<Record1<Object>> columValuesQuery = dslContext.selectDistinct(DSL.field(DSL.name(column.getName()))) | ||
.from(DSL.table(DSL.name(column.getTable().getName()))); | ||
return queryForDistinctValues(columValuesQuery); | ||
} | ||
|
||
private Stream<String> queryForDistinctValues(Select<Record1<Object>> columValuesQuery) { | ||
try { | ||
return sqlExecutionService.fetchStream(columValuesQuery) | ||
.map(record -> record.get(0, String.class)) | ||
// the database might return null or a blank string as a distinct value | ||
.filter(value -> value != null && !value.isBlank()); | ||
} | ||
catch (Exception e) { | ||
log.error("Expecting exactly 1 column in Result when querying for distinct values of a column. Query: {}.", columValuesQuery, e); | ||
} | ||
return Stream.empty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.