|
1180 | 1180 | <a href="#1180" id="1180">1180</a> |
1181 | 1181 | <a href="#1181" id="1181">1181</a> |
1182 | 1182 | <a href="#1182" id="1182">1182</a> |
| 1183 | +<a href="#1183" id="1183">1183</a> |
| 1184 | +<a href="#1184" id="1184">1184</a> |
| 1185 | +<a href="#1185" id="1185">1185</a> |
| 1186 | +<a href="#1186" id="1186">1186</a> |
| 1187 | +<a href="#1187" id="1187">1187</a> |
| 1188 | +<a href="#1188" id="1188">1188</a> |
| 1189 | +<a href="#1189" id="1189">1189</a> |
| 1190 | +<a href="#1190" id="1190">1190</a> |
| 1191 | +<a href="#1191" id="1191">1191</a> |
| 1192 | +<a href="#1192" id="1192">1192</a> |
| 1193 | +<a href="#1193" id="1193">1193</a> |
| 1194 | +<a href="#1194" id="1194">1194</a> |
| 1195 | +<a href="#1195" id="1195">1195</a> |
| 1196 | +<a href="#1196" id="1196">1196</a> |
| 1197 | +<a href="#1197" id="1197">1197</a> |
| 1198 | +<a href="#1198" id="1198">1198</a> |
| 1199 | +<a href="#1199" id="1199">1199</a> |
| 1200 | +<a href="#1200" id="1200">1200</a> |
| 1201 | +<a href="#1201" id="1201">1201</a> |
| 1202 | +<a href="#1202" id="1202">1202</a> |
| 1203 | +<a href="#1203" id="1203">1203</a> |
| 1204 | +<a href="#1204" id="1204">1204</a> |
| 1205 | +<a href="#1205" id="1205">1205</a> |
| 1206 | +<a href="#1206" id="1206">1206</a> |
| 1207 | +<a href="#1207" id="1207">1207</a> |
| 1208 | +<a href="#1208" id="1208">1208</a> |
| 1209 | +<a href="#1209" id="1209">1209</a> |
| 1210 | +<a href="#1210" id="1210">1210</a> |
| 1211 | +<a href="#1211" id="1211">1211</a> |
| 1212 | +<a href="#1212" id="1212">1212</a> |
| 1213 | +<a href="#1213" id="1213">1213</a> |
| 1214 | +<a href="#1214" id="1214">1214</a> |
| 1215 | +<a href="#1215" id="1215">1215</a> |
| 1216 | +<a href="#1216" id="1216">1216</a> |
| 1217 | +<a href="#1217" id="1217">1217</a> |
| 1218 | +<a href="#1218" id="1218">1218</a> |
| 1219 | +<a href="#1219" id="1219">1219</a> |
| 1220 | +<a href="#1220" id="1220">1220</a> |
| 1221 | +<a href="#1221" id="1221">1221</a> |
| 1222 | +<a href="#1222" id="1222">1222</a> |
| 1223 | +<a href="#1223" id="1223">1223</a> |
| 1224 | +<a href="#1224" id="1224">1224</a> |
| 1225 | +<a href="#1225" id="1225">1225</a> |
| 1226 | +<a href="#1226" id="1226">1226</a> |
| 1227 | +<a href="#1227" id="1227">1227</a> |
1183 | 1228 | </pre></div><pre class="rust"><code><span class="comment">// Licensed to the Apache Software Foundation (ASF) under one |
1184 | 1229 | // or more contributor license agreements. See the NOTICE file |
1185 | 1230 | // distributed with this work for additional information |
|
1408 | 1453 | <span class="doccomment">/// Timestamp in microsecond precision, with timezone |
1409 | 1454 | </span>Timestamptz, |
1410 | 1455 | <span class="doccomment">/// Timestamp in nanosecond precision, without timezone |
| 1456 | + </span><span class="attr">#[serde(rename = <span class="string">"timestamp_ns"</span>)] |
1411 | 1457 | </span>TimestampNs, |
1412 | 1458 | <span class="doccomment">/// Timestamp in nanosecond precision with timezone |
| 1459 | + </span><span class="attr">#[serde(rename = <span class="string">"timestamptz_ns"</span>)] |
1413 | 1460 | </span>TimestamptzNs, |
1414 | 1461 | <span class="doccomment">/// Arbitrary-length character sequences encoded in utf-8 |
1415 | 1462 | </span>String, |
|
2037 | 2084 | } |
2038 | 2085 |
|
2039 | 2086 | <span class="attr">#[test] |
2040 | | - </span><span class="kw">fn </span>decimal() { |
| 2087 | + </span><span class="kw">fn </span>primitive_type_serde() { |
2041 | 2088 | <span class="kw">let </span>record = <span class="string">r#" |
2042 | | - { |
2043 | | - "type": "struct", |
2044 | | - "fields": [ |
2045 | | - { |
2046 | | - "id": 1, |
2047 | | - "name": "id", |
2048 | | - "required": true, |
2049 | | - "type": "decimal(9,2)" |
2050 | | - } |
2051 | | - ] |
2052 | | - } |
2053 | | - "#</span>; |
2054 | | - |
2055 | | - check_type_serde( |
2056 | | - record, |
2057 | | - Type::Struct(StructType { |
2058 | | - fields: <span class="macro">vec!</span>[NestedField::required( |
2059 | | - <span class="number">1</span>, |
2060 | | - <span class="string">"id"</span>, |
2061 | | - Type::Primitive(PrimitiveType::Decimal { |
2062 | | - precision: <span class="number">9</span>, |
2063 | | - scale: <span class="number">2</span>, |
2064 | | - }), |
2065 | | - ) |
2066 | | - .into()], |
2067 | | - id_lookup: OnceLock::default(), |
2068 | | - name_lookup: OnceLock::default(), |
2069 | | - }), |
2070 | | - ) |
| 2089 | + { |
| 2090 | + "type": "struct", |
| 2091 | + "fields": [ |
| 2092 | + {"id": 1, "name": "bool_field", "required": true, "type": "boolean"}, |
| 2093 | + {"id": 2, "name": "int_field", "required": true, "type": "int"}, |
| 2094 | + {"id": 3, "name": "long_field", "required": true, "type": "long"}, |
| 2095 | + {"id": 4, "name": "float_field", "required": true, "type": "float"}, |
| 2096 | + {"id": 5, "name": "double_field", "required": true, "type": "double"}, |
| 2097 | + {"id": 6, "name": "decimal_field", "required": true, "type": "decimal(9,2)"}, |
| 2098 | + {"id": 7, "name": "date_field", "required": true, "type": "date"}, |
| 2099 | + {"id": 8, "name": "time_field", "required": true, "type": "time"}, |
| 2100 | + {"id": 9, "name": "timestamp_field", "required": true, "type": "timestamp"}, |
| 2101 | + {"id": 10, "name": "timestamptz_field", "required": true, "type": "timestamptz"}, |
| 2102 | + {"id": 11, "name": "timestamp_ns_field", "required": true, "type": "timestamp_ns"}, |
| 2103 | + {"id": 12, "name": "timestamptz_ns_field", "required": true, "type": "timestamptz_ns"}, |
| 2104 | + {"id": 13, "name": "uuid_field", "required": true, "type": "uuid"}, |
| 2105 | + {"id": 14, "name": "fixed_field", "required": true, "type": "fixed[10]"}, |
| 2106 | + {"id": 15, "name": "binary_field", "required": true, "type": "binary"}, |
| 2107 | + {"id": 16, "name": "string_field", "required": true, "type": "string"} |
| 2108 | + ] |
2071 | 2109 | } |
2072 | | - |
2073 | | - <span class="attr">#[test] |
2074 | | - </span><span class="kw">fn </span>fixed() { |
2075 | | - <span class="kw">let </span>record = <span class="string">r#" |
2076 | | - { |
2077 | | - "type": "struct", |
2078 | | - "fields": [ |
2079 | | - { |
2080 | | - "id": 1, |
2081 | | - "name": "id", |
2082 | | - "required": true, |
2083 | | - "type": "fixed[8]" |
2084 | | - } |
2085 | | - ] |
2086 | | - } |
2087 | | - "#</span>; |
| 2110 | + "#</span>; |
2088 | 2111 |
|
2089 | 2112 | check_type_serde( |
2090 | 2113 | record, |
2091 | 2114 | Type::Struct(StructType { |
2092 | | - fields: <span class="macro">vec!</span>[NestedField::required( |
2093 | | - <span class="number">1</span>, |
2094 | | - <span class="string">"id"</span>, |
2095 | | - Type::Primitive(PrimitiveType::Fixed(<span class="number">8</span>)), |
2096 | | - ) |
2097 | | - .into()], |
| 2115 | + fields: <span class="macro">vec!</span>[ |
| 2116 | + NestedField::required(<span class="number">1</span>, <span class="string">"bool_field"</span>, Type::Primitive(PrimitiveType::Boolean)) |
| 2117 | + .into(), |
| 2118 | + NestedField::required(<span class="number">2</span>, <span class="string">"int_field"</span>, Type::Primitive(PrimitiveType::Int)) |
| 2119 | + .into(), |
| 2120 | + NestedField::required(<span class="number">3</span>, <span class="string">"long_field"</span>, Type::Primitive(PrimitiveType::Long)) |
| 2121 | + .into(), |
| 2122 | + NestedField::required(<span class="number">4</span>, <span class="string">"float_field"</span>, Type::Primitive(PrimitiveType::Float)) |
| 2123 | + .into(), |
| 2124 | + NestedField::required( |
| 2125 | + <span class="number">5</span>, |
| 2126 | + <span class="string">"double_field"</span>, |
| 2127 | + Type::Primitive(PrimitiveType::Double), |
| 2128 | + ) |
| 2129 | + .into(), |
| 2130 | + NestedField::required( |
| 2131 | + <span class="number">6</span>, |
| 2132 | + <span class="string">"decimal_field"</span>, |
| 2133 | + Type::Primitive(PrimitiveType::Decimal { |
| 2134 | + precision: <span class="number">9</span>, |
| 2135 | + scale: <span class="number">2</span>, |
| 2136 | + }), |
| 2137 | + ) |
| 2138 | + .into(), |
| 2139 | + NestedField::required(<span class="number">7</span>, <span class="string">"date_field"</span>, Type::Primitive(PrimitiveType::Date)) |
| 2140 | + .into(), |
| 2141 | + NestedField::required(<span class="number">8</span>, <span class="string">"time_field"</span>, Type::Primitive(PrimitiveType::Time)) |
| 2142 | + .into(), |
| 2143 | + NestedField::required( |
| 2144 | + <span class="number">9</span>, |
| 2145 | + <span class="string">"timestamp_field"</span>, |
| 2146 | + Type::Primitive(PrimitiveType::Timestamp), |
| 2147 | + ) |
| 2148 | + .into(), |
| 2149 | + NestedField::required( |
| 2150 | + <span class="number">10</span>, |
| 2151 | + <span class="string">"timestamptz_field"</span>, |
| 2152 | + Type::Primitive(PrimitiveType::Timestamptz), |
| 2153 | + ) |
| 2154 | + .into(), |
| 2155 | + NestedField::required( |
| 2156 | + <span class="number">11</span>, |
| 2157 | + <span class="string">"timestamp_ns_field"</span>, |
| 2158 | + Type::Primitive(PrimitiveType::TimestampNs), |
| 2159 | + ) |
| 2160 | + .into(), |
| 2161 | + NestedField::required( |
| 2162 | + <span class="number">12</span>, |
| 2163 | + <span class="string">"timestamptz_ns_field"</span>, |
| 2164 | + Type::Primitive(PrimitiveType::TimestamptzNs), |
| 2165 | + ) |
| 2166 | + .into(), |
| 2167 | + NestedField::required(<span class="number">13</span>, <span class="string">"uuid_field"</span>, Type::Primitive(PrimitiveType::Uuid)) |
| 2168 | + .into(), |
| 2169 | + NestedField::required( |
| 2170 | + <span class="number">14</span>, |
| 2171 | + <span class="string">"fixed_field"</span>, |
| 2172 | + Type::Primitive(PrimitiveType::Fixed(<span class="number">10</span>)), |
| 2173 | + ) |
| 2174 | + .into(), |
| 2175 | + NestedField::required( |
| 2176 | + <span class="number">15</span>, |
| 2177 | + <span class="string">"binary_field"</span>, |
| 2178 | + Type::Primitive(PrimitiveType::Binary), |
| 2179 | + ) |
| 2180 | + .into(), |
| 2181 | + NestedField::required( |
| 2182 | + <span class="number">16</span>, |
| 2183 | + <span class="string">"string_field"</span>, |
| 2184 | + Type::Primitive(PrimitiveType::String), |
| 2185 | + ) |
| 2186 | + .into(), |
| 2187 | + ], |
2098 | 2188 | id_lookup: OnceLock::default(), |
2099 | 2189 | name_lookup: OnceLock::default(), |
2100 | 2190 | }), |
|
0 commit comments