Skip to content

Commit

Permalink
feat: add stream write samples for range (#780)
Browse files Browse the repository at this point in the history
* feat: add stream write samples for range

* lint
  • Loading branch information
Linchin authored Apr 30, 2024
1 parent 22a89c5 commit 27dbbc2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
8 changes: 8 additions & 0 deletions samples/snippets/append_rows_proto2.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ def append_rows_proto2(project_id: str, dataset_id: str, table_id: str):
row.struct_list.append(sub_message)
proto_rows.serialized_rows.append(row.SerializeToString())

row = sample_data_pb2.SampleData()
row.row_num = 16
date_value = datetime.date(2021, 8, 8)
epoch_value = datetime.date(1970, 1, 1)
delta = date_value - epoch_value
row.range_date.start = delta.days
proto_rows.serialized_rows.append(row.SerializeToString())

request = types.AppendRowsRequest()
request.offset = 12
proto_data = types.AppendRowsRequest.ProtoData()
Expand Down
11 changes: 10 additions & 1 deletion samples/snippets/sample_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ message SampleData {
optional int64 sub_int_col = 1;
}

message RangeValue {
optional int32 start = 1;
optional int32 end = 2;
}

// The following types map directly between protocol buffers and their
// corresponding BigQuery data types.
optional bool bool_col = 1;
Expand All @@ -55,7 +60,11 @@ message SampleData {
optional SampleStruct struct_col = 14;
repeated SampleStruct struct_list = 15;

// Range types, see:
// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#range_type
optional RangeValue range_date = 16;

// Use the required keyword for client-side validation of required fields.
required int64 row_num = 16;
required int64 row_num = 17;
}
// [END bigquerystorage_append_rows_raw_proto2_definition]
39 changes: 9 additions & 30 deletions samples/snippets/sample_data_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions samples/snippets/sample_data_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,10 @@
{"name": "sub_int_col", "type": "INTEGER"}
],
"mode": "REPEATED"
},
{
"name": "range_date",
"type": "RANGE",
"rangeElementType": {"type": "DATE"}
}
]

0 comments on commit 27dbbc2

Please sign in to comment.