type.proto 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // Copyright 2022 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.spanner.v1;
  16. import "google/api/field_behavior.proto";
  17. option csharp_namespace = "Google.Cloud.Spanner.V1";
  18. option go_package = "google.golang.org/genproto/googleapis/spanner/v1;spanner";
  19. option java_multiple_files = true;
  20. option java_outer_classname = "TypeProto";
  21. option java_package = "com.google.spanner.v1";
  22. option php_namespace = "Google\\Cloud\\Spanner\\V1";
  23. option ruby_package = "Google::Cloud::Spanner::V1";
  24. // `Type` indicates the type of a Cloud Spanner value, as might be stored in a
  25. // table cell or returned from an SQL query.
  26. message Type {
  27. // Required. The [TypeCode][google.spanner.v1.TypeCode] for this type.
  28. TypeCode code = 1 [(google.api.field_behavior) = REQUIRED];
  29. // If [code][google.spanner.v1.Type.code] == [ARRAY][google.spanner.v1.TypeCode.ARRAY], then `array_element_type`
  30. // is the type of the array elements.
  31. Type array_element_type = 2;
  32. // If [code][google.spanner.v1.Type.code] == [STRUCT][google.spanner.v1.TypeCode.STRUCT], then `struct_type`
  33. // provides type information for the struct's fields.
  34. StructType struct_type = 3;
  35. // The [TypeAnnotationCode][google.spanner.v1.TypeAnnotationCode] that disambiguates SQL type that Spanner will
  36. // use to represent values of this type during query processing. This is
  37. // necessary for some type codes because a single [TypeCode][google.spanner.v1.TypeCode] can be mapped
  38. // to different SQL types depending on the SQL dialect. [type_annotation][google.spanner.v1.Type.type_annotation]
  39. // typically is not needed to process the content of a value (it doesn't
  40. // affect serialization) and clients can ignore it on the read path.
  41. TypeAnnotationCode type_annotation = 4;
  42. }
  43. // `StructType` defines the fields of a [STRUCT][google.spanner.v1.TypeCode.STRUCT] type.
  44. message StructType {
  45. // Message representing a single field of a struct.
  46. message Field {
  47. // The name of the field. For reads, this is the column name. For
  48. // SQL queries, it is the column alias (e.g., `"Word"` in the
  49. // query `"SELECT 'hello' AS Word"`), or the column name (e.g.,
  50. // `"ColName"` in the query `"SELECT ColName FROM Table"`). Some
  51. // columns might have an empty name (e.g., `"SELECT
  52. // UPPER(ColName)"`). Note that a query result can contain
  53. // multiple fields with the same name.
  54. string name = 1;
  55. // The type of the field.
  56. Type type = 2;
  57. }
  58. // The list of fields that make up this struct. Order is
  59. // significant, because values of this struct type are represented as
  60. // lists, where the order of field values matches the order of
  61. // fields in the [StructType][google.spanner.v1.StructType]. In turn, the order of fields
  62. // matches the order of columns in a read request, or the order of
  63. // fields in the `SELECT` clause of a query.
  64. repeated Field fields = 1;
  65. }
  66. // `TypeCode` is used as part of [Type][google.spanner.v1.Type] to
  67. // indicate the type of a Cloud Spanner value.
  68. //
  69. // Each legal value of a type can be encoded to or decoded from a JSON
  70. // value, using the encodings described below. All Cloud Spanner values can
  71. // be `null`, regardless of type; `null`s are always encoded as a JSON
  72. // `null`.
  73. enum TypeCode {
  74. // Not specified.
  75. TYPE_CODE_UNSPECIFIED = 0;
  76. // Encoded as JSON `true` or `false`.
  77. BOOL = 1;
  78. // Encoded as `string`, in decimal format.
  79. INT64 = 2;
  80. // Encoded as `number`, or the strings `"NaN"`, `"Infinity"`, or
  81. // `"-Infinity"`.
  82. FLOAT64 = 3;
  83. // Encoded as `string` in RFC 3339 timestamp format. The time zone
  84. // must be present, and must be `"Z"`.
  85. //
  86. // If the schema has the column option
  87. // `allow_commit_timestamp=true`, the placeholder string
  88. // `"spanner.commit_timestamp()"` can be used to instruct the system
  89. // to insert the commit timestamp associated with the transaction
  90. // commit.
  91. TIMESTAMP = 4;
  92. // Encoded as `string` in RFC 3339 date format.
  93. DATE = 5;
  94. // Encoded as `string`.
  95. STRING = 6;
  96. // Encoded as a base64-encoded `string`, as described in RFC 4648,
  97. // section 4.
  98. BYTES = 7;
  99. // Encoded as `list`, where the list elements are represented
  100. // according to
  101. // [array_element_type][google.spanner.v1.Type.array_element_type].
  102. ARRAY = 8;
  103. // Encoded as `list`, where list element `i` is represented according
  104. // to [struct_type.fields[i]][google.spanner.v1.StructType.fields].
  105. STRUCT = 9;
  106. // Encoded as `string`, in decimal format or scientific notation format.
  107. // <br>Decimal format:
  108. // <br>`[+-]Digits[.[Digits]]` or
  109. // <br>`[+-][Digits].Digits`
  110. //
  111. // Scientific notation:
  112. // <br>`[+-]Digits[.[Digits]][ExponentIndicator[+-]Digits]` or
  113. // <br>`[+-][Digits].Digits[ExponentIndicator[+-]Digits]`
  114. // <br>(ExponentIndicator is `"e"` or `"E"`)
  115. NUMERIC = 10;
  116. // Encoded as a JSON-formatted `string` as described in RFC 7159. The
  117. // following rules are applied when parsing JSON input:
  118. //
  119. // - Whitespace characters are not preserved.
  120. // - If a JSON object has duplicate keys, only the first key is preserved.
  121. // - Members of a JSON object are not guaranteed to have their order
  122. // preserved.
  123. // - JSON array elements will have their order preserved.
  124. JSON = 11;
  125. }
  126. // `TypeAnnotationCode` is used as a part of [Type][google.spanner.v1.Type] to
  127. // disambiguate SQL types that should be used for a given Cloud Spanner value.
  128. // Disambiguation is needed because the same Cloud Spanner type can be mapped to
  129. // different SQL types depending on SQL dialect. TypeAnnotationCode doesn't
  130. // affect the way value is serialized.
  131. enum TypeAnnotationCode {
  132. // Not specified.
  133. TYPE_ANNOTATION_CODE_UNSPECIFIED = 0;
  134. // PostgreSQL compatible NUMERIC type. This annotation needs to be applied to
  135. // [Type][google.spanner.v1.Type] instances having [NUMERIC][google.spanner.v1.TypeCode.NUMERIC]
  136. // type code to specify that values of this type should be treated as
  137. // PostgreSQL NUMERIC values. Currently this annotation is always needed for
  138. // [NUMERIC][google.spanner.v1.TypeCode.NUMERIC] when a client interacts with PostgreSQL-enabled
  139. // Spanner databases.
  140. PG_NUMERIC = 2;
  141. // PostgreSQL compatible JSONB type. This annotation needs to be applied to
  142. // [Type][google.spanner.v1.Type] instances having [JSON][google.spanner.v1.TypeCode.JSON]
  143. // type code to specify that values of this type should be treated as
  144. // PostgreSQL JSONB values. Currently this annotation is always needed for
  145. // [JSON][google.spanner.v1.TypeCode.JSON] when a client interacts with PostgreSQL-enabled
  146. // Spanner databases.
  147. PG_JSONB = 3;
  148. }