// Proto messages and service definition for the APIs related to querying data. edition = "2023"; package datasets.v1; import "buf/validate/validate.proto"; import "datasets/v1/core.proto"; import "datasets/v1/well_known_types.proto"; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; import "tilebox/v1/id.proto"; import "tilebox/v1/query.proto"; option features.field_presence = IMPLICIT; // QueryByIDRequest contains the request parameters for retrieving a single data point by its id. message QueryByIDRequest { // The dataset id to query. If not set, the dataset is derived from the collection ids, in which case there must be at least one collection id set. tilebox.v1.ID dataset_id = 4; // collection ids to query. repeated tilebox.v1.ID collection_ids = 1 [(buf.validate.field).repeated = { min_items: 0 max_items: 100 }]; // The id of the requested data point. tilebox.v1.ID id = 2 [(buf.validate.field).required = true]; // If true, only the datapoint metadata is returned. bool skip_data = 3; } // QueryFilters contains the filters to apply to a query. message QueryFilters { option (buf.validate.message).oneof = { fields: [ "time_interval", "datapoint_interval" ] }; // The time interval to query data points for. If absent or neither bound is set, the query covers the full available // time range. If only start_time is set, it is used as the lower bound. If only end_time is set, it is used as the // upper bound. start_exclusive and end_inclusive control whether each bound is included, meaning data points // that fall exactly on the same millisecond as the bounds. Only one of time_interval or datapoint_interval can be set. tilebox.v1.TimeInterval time_interval = 1; // Instead of filtering by time, the query can filter by a range of data point ids. The same open-ended interval // semantics apply as for time_interval. Only one of time_interval or datapoint_interval can be set. tilebox.v1.IDInterval datapoint_interval = 2; SpatialFilter spatial_extent = 3; // Additional expressions over fields marked queryable in the dataset schema. // All top-level expressions are combined with each other and with the interval and spatial filters using logical AND. // Use a nested LogicalExpression for explicit OR, NOT, or grouped boolean logic. repeated FilterExpression expressions = 4 [(buf.validate.field).repeated.max_items = 64]; } // FilterExpression supports Basic CQL2 property-to-literal comparisons and custom enum array predicates. // Expressions use three-valued Boolean logic compatible with SQL and CQL2: true, false, and null (unknown). A datapoint // matches only when the complete filter expression evaluates to true; false and null results are excluded. message FilterExpression { option (buf.validate.message).oneof = { fields: [ "logical", "comparison", "is_null", "array_predicate" ] required: true }; // Exactly one expression node must be set. LogicalExpression logical = 1; FieldComparison comparison = 2; FieldNullCheck is_null = 3; FieldArrayPredicate array_predicate = 4; } // FieldArrayPredicate tests membership of public values in a queryable repeated custom enum field. // Values are case-sensitive and must belong to the field's vocabulary. Order and duplicates do not affect matching. // Omitted and empty fields both represent the empty set. // CONTAINS_ALL with no values is true; OVERLAPS with no values is false. These predicates never return null. // Scalar comparisons and null checks are not supported on repeated fields. message FieldArrayPredicate { // Name of a top-level queryable repeated custom enum field. string field_name = 1 [(buf.validate.field).string = { min_len: 1 max_len: 100 pattern: "^[a-z][a-z0-9_]*$" }]; FieldArrayOperator operator = 2 [(buf.validate.field).enum = { defined_only: true not_in: [0] }]; // Public enum values, not protobuf symbols or numbers. An empty list is allowed. repeated string values = 3 [(buf.validate.field).repeated = { max_items: 100 items: { string: {min_len: 1} } }]; } // FieldArrayOperator selects a CQL2 set-membership operation. enum FieldArrayOperator { FIELD_ARRAY_OPERATOR_UNSPECIFIED = 0; // CQL2 A_CONTAINS: the field contains every requested value. FIELD_ARRAY_OPERATOR_CONTAINS_ALL = 1; // CQL2 A_OVERLAPS: the field contains at least one requested value. FIELD_ARRAY_OPERATOR_OVERLAPS = 2; } // LogicalExpression combines nested filter expressions using SQL- and CQL2-compatible three-valued Boolean logic. // AND, OR, and NOT propagate null according to their standard truth tables; in particular, NOT(null) evaluates to null. message LogicalExpression { option (buf.validate.message).cel = { id: "logical_expression.operand_arity" message: "NOT requires exactly one operand; AND and OR require at least two" expression: "this.operator == 3 ? this.operands.size() == 1 : this.operands.size() >= 2" }; // The logical operation to apply to operands. LogicalOperator operator = 1 [(buf.validate.field).enum = { defined_only: true not_in: [0] }]; // Operands for the logical operation. AND and OR require at least two; NOT requires exactly one. repeated FilterExpression operands = 2 [(buf.validate.field).repeated = { min_items: 1 max_items: 64 }]; } // LogicalOperator specifies how nested filter expressions are combined. enum LogicalOperator { LOGICAL_OPERATOR_UNSPECIFIED = 0; LOGICAL_OPERATOR_AND = 1; LOGICAL_OPERATOR_OR = 2; LOGICAL_OPERATOR_NOT = 3; } // FieldComparison compares a queryable dataset field to a typed literal value. // Every comparison evaluates to null (unknown) when the field is absent or explicitly null, including NOT_EQUAL. // Consequently, both `field != value` and `NOT(field == value)` require the field to be present. To include absent or // null fields, explicitly combine the comparison with FieldNullCheck using OR. // Scalar enum fields support only EQUAL and NOT_EQUAL. Use a LogicalExpression with OR over equality comparisons to match // any of several members. Unknown enum values, numeric enum literals, and ordering comparisons are invalid arguments. // For repeated custom enums, use FieldArrayPredicate instead. message FieldComparison { // Name of a top-level field in the dataset schema. string field_name = 1 [(buf.validate.field).string = { min_len: 1 max_len: 100 pattern: "^[a-z][a-z0-9_]*$" }]; // Comparison operation to apply. FieldComparisonOperator operator = 2 [(buf.validate.field).enum = { defined_only: true not_in: [0] }]; // Literal value, interpreted using the field's schema. For custom enums, use string_value with a value from // FieldAnnotation.enum_values. FieldQueryValue value = 3 [(buf.validate.field).required = true]; } // FieldComparisonOperator specifies a Basic CQL2 comparison operation. enum FieldComparisonOperator { FIELD_COMPARISON_OPERATOR_UNSPECIFIED = 0; FIELD_COMPARISON_OPERATOR_EQUAL = 1; FIELD_COMPARISON_OPERATOR_NOT_EQUAL = 2; FIELD_COMPARISON_OPERATOR_LESS_THAN = 3; FIELD_COMPARISON_OPERATOR_LESS_THAN_OR_EQUAL = 4; FIELD_COMPARISON_OPERATOR_GREATER_THAN = 5; FIELD_COMPARISON_OPERATOR_GREATER_THAN_OR_EQUAL = 6; } // FieldNullCheck matches datapoints for which a queryable field is absent or explicitly null. These states are // equivalent for filtering. IS NOT NULL is represented by wrapping this expression in LOGICAL_OPERATOR_NOT and matches // only datapoints for which the field is present and non-null. message FieldNullCheck { // Name of a top-level field in the dataset schema. string field_name = 1 [(buf.validate.field).string = { min_len: 1 max_len: 100 pattern: "^[a-z][a-z0-9_]*$" }]; } // FieldQueryValue is a typed scalar or well-known-type literal used in a field comparison. message FieldQueryValue { option (buf.validate.message).oneof = { fields: [ "bool_value", "int64_value", "uint64_value", "double_value", "string_value", "timestamp_value", "duration_value", "bytes_value" ] required: true }; reserved 8; reserved enum_name; // Exactly one typed literal must be set. Explicit presence preserves zero and empty values. bool bool_value = 1 [features.field_presence = EXPLICIT]; int64 int64_value = 2 [features.field_presence = EXPLICIT]; uint64 uint64_value = 3 [features.field_presence = EXPLICIT]; double double_value = 4 [features.field_presence = EXPLICIT]; // Text for a string field, or a value from FieldAnnotation.enum_values for a custom enum, e.g. "L1". // The server resolves enum values to their numbers. Matching is case-sensitive; unknown values are rejected. // Generated protobuf names are not accepted here unless they are also declared public values. string string_value = 5 [features.field_presence = EXPLICIT]; google.protobuf.Timestamp timestamp_value = 6; google.protobuf.Duration duration_value = 7; bytes bytes_value = 9 [features.field_presence = EXPLICIT]; } // SpatialFilterMode specifies how geometries are compared to a given spatial filter. enum SpatialFilterMode { // Unspecified spatial filter mode, will default to intersects. SPATIAL_FILTER_MODE_UNSPECIFIED = 0; // Any geometry that intersects the filter geometry is included. SPATIAL_FILTER_MODE_INTERSECTS = 1; // Only datapoint geometries fully contained within the filter geometry are included. SPATIAL_FILTER_MODE_FILTER_CONTAINS_GEOMETRY = 2; // Only datapoint geometries that fully contain the filter geometry are included. SPATIAL_FILTER_MODE_GEOMETRY_CONTAINS_FILTER = 3; } // SpatialCoordinateSystem specifies the coordinate system in which to perform geometry calculations such as // intersections. enum SpatialCoordinateSystem { // Unspecified coordinate system, will default to cartesian. SPATIAL_COORDINATE_SYSTEM_UNSPECIFIED = 0; // Cartesian (lat/lon) coordinate system SPATIAL_COORDINATE_SYSTEM_CARTESIAN = 1; // Spherical (x/y/z) coordinate system SPATIAL_COORDINATE_SYSTEM_SPHERICAL = 2; } // SpatialFilter defines a spatial filter operation as part of a query. message SpatialFilter { // The geometry to filter by. Geometry geometry = 1 [(buf.validate.field).required = true]; // How to compare datapoint geometries with the filter geometry. SpatialFilterMode mode = 2 [(buf.validate.field).enum.defined_only = true]; // Coordinate system in which to perform geometry calculations. SpatialCoordinateSystem coordinate_system = 3 [(buf.validate.field).enum.defined_only = true]; } // QueryRequest contains the request parameters for retrieving data from a Tilebox dataset. message QueryRequest { // The dataset id to query. If not set, the dataset is derived from the collection ids, in which case there must be at least one collection id set. tilebox.v1.ID dataset_id = 5; // collection ids to query. If empty, all collections of the dataset are queried. repeated tilebox.v1.ID collection_ids = 1 [(buf.validate.field).repeated = { min_items: 0 max_items: 100 }]; // Filters to apply to the query. QueryFilters filters = 2; // The pagination parameters for this request. tilebox.v1.Pagination page = 3 [features.field_presence = EXPLICIT]; // If true, only datapoint metadata, such as id, time and ingestion_time are returned. bool skip_data = 4; } // QueryResultPage is a single page of data points of a Tilebox dataset message QueryResultPage { // The datapoints. RepeatedAny data = 1; // The pagination parameters for the next page. tilebox.v1.Pagination next_page = 2 [features.field_presence = EXPLICIT]; } // DataAccessService provides data access and querying capabilities for Tilebox datasets. service DataAccessService { // QueryByID returns a single data point by its ID. rpc QueryByID(QueryByIDRequest) returns (Any) {} // Query returns a list of data points matching the given query filters. rpc Query(QueryRequest) returns (QueryResultPage) {} }