Skip to content

Fix query view with filter for bigquery connector #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions wren-base/src/main/java/io/wren/base/WrenMDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private static Optional<io.wren.base.dto.Column> getColumn(Model model, String n
.findAny();
}

public String getColumnType(String objectName, String columnName)
public Optional<String> getColumnType(String objectName, String columnName)
{
if (!isObjectExist(objectName)) {
throw new IllegalArgumentException("Dataset " + objectName + " not found");
Expand All @@ -279,26 +279,27 @@ public String getColumnType(String objectName, String columnName)
return getModel(objectName).get().getColumns().stream()
.filter(column -> columnName.equals(column.getName()))
.map(io.wren.base.dto.Column::getType)
.findAny()
.orElseThrow(() -> new IllegalArgumentException("Column " + columnName + " not found in " + objectName));
.findAny();
}
else if (getMetric(objectName).isPresent()) {
return getMetric(objectName).get().getColumns().stream()
.filter(column -> columnName.equals(column.getName()))
.map(Column::getType)
.findAny()
.orElseThrow(() -> new IllegalArgumentException("Column " + columnName + " not found in " + objectName));
.findAny();
}
else if (getCumulativeMetric(objectName).isPresent()) {
CumulativeMetric cumulativeMetric = getCumulativeMetric(objectName).get();
if (cumulativeMetric.getMeasure().getName().equals(columnName)) {
return cumulativeMetric.getMeasure().getType();
return Optional.of(cumulativeMetric.getMeasure().getType());
}
if (cumulativeMetric.getWindow().getName().equals(columnName)) {
return getColumnType(cumulativeMetric.getBaseObject(), cumulativeMetric.getWindow().getRefColumn());
}
}
throw new IllegalArgumentException("Dataset " + objectName + " is not a model, metric or cumulative metric");
else if (getView(objectName).isPresent()) {
return Optional.empty();
}
throw new IllegalArgumentException("Dataset " + objectName + " is not a model, metric, cumulative metric or view");
}

public DateSpine getDateSpine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private PGType<?> getColumnType(Field field)
if (!mdl.isObjectExist(objectName)) {
return null;
}
return PGTypes.nameToPgType(mdl.getColumnType(objectName, columnName)).orElse(null);
return mdl.getColumnType(objectName, columnName).flatMap(PGTypes::nameToPgType).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public void syncPgMetastore()
metric.getMeasure().getName(),
pgMetastore.handlePgType(metric.getMeasure().getType()),
metric.getWindow().getName(),
mdl.getColumnType(metric.getName(), metric.getWindow().getName()));
mdl.getColumnType(metric.getName(), metric.getWindow().getName())
.orElseThrow(() -> new IllegalArgumentException("Unknown window column type")));
sb.append(format("CREATE TABLE IF NOT EXISTS \"%s\".\"%s\" (%s);\n", mdl.getSchema(), metric.getName(), cols));
});
mdl.listViews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.stream.Collectors;

import static io.wren.base.Utils.checkArgument;
import static io.wren.base.type.AnyType.ANY;
import static io.wren.main.web.WrenExceptionMapper.bindAsyncResponse;
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void getColumnLineage(
.map(entry -> new LineageResult(
entry.getKey(),
entry.getValue().stream().map(column ->
new LineageResult.Column(column, Map.of("type", mdl.getColumnType(entry.getKey(), column)))).collect(toList())))
new LineageResult.Column(column, Map.of("type", mdl.getColumnType(entry.getKey(), column).orElse(ANY.typName())))).collect(toList())))
.collect(Collectors.toList());
})
.whenComplete(bindAsyncResponse(asyncResponse));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,11 @@ public void testView()
ResultSet resultSet = stmt.executeQuery("SELECT * FROM \"selectOrders\"");
resultSet.next();
});

assertThatNoException().isThrownBy(() -> {
ResultSet resultSet = stmt.executeQuery("SELECT * FROM \"selectOrders\" WHERE orderkey = 111");
resultSet.next();
});
ResultSet viewResultSet = conn.getMetaData().getTables(null, null, "selectOrders", null);
assertThat(viewResultSet.next()).isTrue();
// TODO: jdbc describe wrong type
Expand Down
Loading