Skip to content
Open
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
1 change: 1 addition & 0 deletions willow/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ cc_test(
srcs = ["client_test.cc"],
deps = [
":client_cc",
"@protobuf//:duration_cc_proto",
"@googletest//:gtest_main",
"@abseil-cpp//absl/status",
"//ffi_utils:status_matchers",
Expand Down
20 changes: 13 additions & 7 deletions willow/api/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "include/cxx.h"
#include "willow/api/client.rs.h"
#include "willow/input_encoding/codec.h"
#include "willow/input_encoding/codec_factory.h"
#include "willow/proto/shell/ciphertexts.pb.h"
#include "willow/proto/willow/aggregation_config.pb.h"
#include "willow/proto/willow/input_spec.pb.h"
Expand All @@ -49,14 +50,19 @@ absl::StatusOr<willow::AggregationConfigProto> CreateAggregationConfig(
// of group-by domains.
int64_t flattened_domain_size = 1;
for (const auto& group_by_spec : input_spec_proto.group_by_vector_specs()) {
if (group_by_spec.domain_spec().string_values().values_size() == 0) {
return absl::InvalidArgumentError(absl::StrCat(
"Missing domain, invalid domain type (must be StringValues), or "
"empty string_values for group by vector: ",
group_by_spec.vector_name()));
if (!group_by_spec.domain_spec().has_time() &&
!group_by_spec.domain_spec().has_string_values()) {
return absl::InvalidArgumentError(
absl::StrCat("Unsupported domain type for group-by vector: ",
group_by_spec.vector_name()));
}
flattened_domain_size *=
group_by_spec.domain_spec().string_values().values_size();
int domain_size = willow::CodecFactory::GetDomainSize(group_by_spec);
if (domain_size <= 0) {
return absl::InvalidArgumentError(
absl::StrCat("Empty or invalid domain size for group by vector: ",
group_by_spec.vector_name()));
}
flattened_domain_size *= domain_size;
}
// Build VectorConfig (length and bound) for each metric.
for (const auto& metric_spec : input_spec_proto.metric_vector_specs()) {
Expand Down
28 changes: 28 additions & 0 deletions willow/api/client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "absl/status/status.h"
#include "ffi_utils/status_matchers.h"
#include "gmock/gmock.h"
#include "google/protobuf/duration.pb.h"
#include "gtest/gtest.h"
#include "willow/input_encoding/codec.h"
#include "willow/input_encoding/codec_factory.h"
Expand Down Expand Up @@ -185,6 +186,33 @@ TEST(WillowShellClientTest, CreateAggregationConfigDefaultBound) {
EXPECT_EQ(vector_configs.at("metric1").bound(), default_bound);
}

TEST(WillowShellClientTest, CreateAggregationConfigSuccessWithTimeDomain) {
InputSpec input_spec;
auto* metric_spec = input_spec.add_metric_vector_specs();
metric_spec->set_vector_name("metric1");
metric_spec->set_data_type(InputSpec::INT64);
metric_spec->mutable_domain_spec()->mutable_interval()->set_max(100);

auto* group_by_spec = input_spec.add_group_by_vector_specs();
group_by_spec->set_vector_name("time");
group_by_spec->set_data_type(InputSpec::STRING);
auto* time_domain = group_by_spec->mutable_domain_spec()->mutable_time();
time_domain->mutable_period_duration()->set_seconds(86400); // 1 day
time_domain->set_num_periods(6);
time_domain->set_timezone("UTC");

SECAGG_ASSERT_OK_AND_ASSIGN(
AggregationConfigProto config,
CreateAggregationConfig(input_spec, /*key_id=*/"test",
/*max_number_of_clients=*/10));

// Expected flattened_domain_size = num_periods + 1 = 7
const auto& vector_configs = config.vector_configs();
ASSERT_TRUE(vector_configs.contains("metric1"));
EXPECT_EQ(vector_configs.at("metric1").length(), 7);
EXPECT_EQ(vector_configs.at("metric1").bound(), 100);
}

TEST(WillowShellClientTest, CreateAggregationConfigFailsOnEmptyDomain) {
InputSpec input_spec = CreateTestInputSpecProto();
ASSERT_GT(input_spec.group_by_vector_specs_size(), 0);
Expand Down
40 changes: 40 additions & 0 deletions willow/input_encoding/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ package(
default_visibility = ["//visibility:public"],
)

cc_library(
name = "time_utils",
srcs = [
"time_utils.cc",
],
hdrs = [
"time_utils.h",
],
deps = [
"@protobuf//:duration_cc_proto",
"@protobuf//:timestamp_cc_proto",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"//willow/proto/willow:input_spec_cc_proto",
],
)

cc_library(
name = "codec",
srcs = [
Expand All @@ -33,12 +52,15 @@ cc_library(
"codec_factory.h",
],
deps = [
":time_utils",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/memory",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"//ffi_utils:status_macros",
"//willow/proto/willow:input_spec_cc_proto",
],
)
Expand All @@ -48,15 +70,33 @@ cc_test(
srcs = ["explicit_codec_test.cc"],
deps = [
":codec",
":time_utils",
"@protobuf//:duration_cc_proto",
"@googletest//:gtest_main",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/time",
"//ffi_utils:status_matchers",
"//willow/proto/willow:input_spec_cc_proto",
"//willow/testing_utils:testing_utils_cc",
],
)

cc_test(
name = "time_utils_test",
srcs = ["time_utils_test.cc"],
deps = [
":time_utils",
"@protobuf//:duration_cc_proto",
"@protobuf//:timestamp_cc_proto",
"@googletest//:gtest_main",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/time",
"//ffi_utils:status_matchers",
"//willow/proto/willow:input_spec_cc_proto",
],
)

pytype_pybind_extension(
name = "codec_bindings",
srcs = ["codec_bindings.cc"],
Expand Down
6 changes: 6 additions & 0 deletions willow/input_encoding/codec_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ PYBIND11_MODULE(codec_bindings, m) {
return self.ValidateExampleQuery(cpp_map);
});

// Creates an ExplicitCodec from a serialized InputSpec.
//
// Remark: 'encoding_time' and 'decoding_anchor_time' are not exposed to
// Python because these bindings are currently only used to validate example
// queries (ValidateExampleQuery), which does not require encoding or
// decoding.
m.def(
"CreateExplicitCodec",
[](const std::string& serialized_input_spec)
Expand Down
Loading