Skip to content

Commit f5dafda

Browse files
Linchinparthea
authored andcommitted
feat: add stream write samples for range (#780)
* feat: add stream write samples for range * lint
1 parent 971d708 commit f5dafda

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

packages/google-cloud-bigquery-storage/samples/snippets/append_rows_proto2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ def append_rows_proto2(project_id: str, dataset_id: str, table_id: str):
214214
row.struct_list.append(sub_message)
215215
proto_rows.serialized_rows.append(row.SerializeToString())
216216

217+
row = sample_data_pb2.SampleData()
218+
row.row_num = 16
219+
date_value = datetime.date(2021, 8, 8)
220+
epoch_value = datetime.date(1970, 1, 1)
221+
delta = date_value - epoch_value
222+
row.range_date.start = delta.days
223+
proto_rows.serialized_rows.append(row.SerializeToString())
224+
217225
request = types.AppendRowsRequest()
218226
request.offset = 12
219227
proto_data = types.AppendRowsRequest.ProtoData()

packages/google-cloud-bigquery-storage/samples/snippets/sample_data.proto

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ message SampleData {
2929
optional int64 sub_int_col = 1;
3030
}
3131

32+
message RangeValue {
33+
optional int32 start = 1;
34+
optional int32 end = 2;
35+
}
36+
3237
// The following types map directly between protocol buffers and their
3338
// corresponding BigQuery data types.
3439
optional bool bool_col = 1;
@@ -55,7 +60,11 @@ message SampleData {
5560
optional SampleStruct struct_col = 14;
5661
repeated SampleStruct struct_list = 15;
5762

63+
// Range types, see:
64+
// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#range_type
65+
optional RangeValue range_date = 16;
66+
5867
// Use the required keyword for client-side validation of required fields.
59-
required int64 row_num = 16;
68+
required int64 row_num = 17;
6069
}
6170
// [END bigquerystorage_append_rows_raw_proto2_definition]

packages/google-cloud-bigquery-storage/samples/snippets/sample_data_pb2.py

Lines changed: 9 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/google-cloud-bigquery-storage/samples/snippets/sample_data_schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,10 @@
7272
{"name": "sub_int_col", "type": "INTEGER"}
7373
],
7474
"mode": "REPEATED"
75+
},
76+
{
77+
"name": "range_date",
78+
"type": "RANGE",
79+
"rangeElementType": {"type": "DATE"}
7580
}
7681
]

0 commit comments

Comments
 (0)