@@ -1156,86 +1156,85 @@ pub enum TableFactor {
1156
1156
1157
1157
pub enum TableSampleKind {
1158
1158
/// Table sample located before the table alias option
1159
- BeforeTableAlias ( Box < TableSampleMethod > ) ,
1159
+ BeforeTableAlias ( Box < TableSample > ) ,
1160
1160
/// Table sample located after the table alias option
1161
- AfterTableAlias ( Box < TableSampleMethod > ) ,
1161
+ AfterTableAlias ( Box < TableSample > ) ,
1162
1162
}
1163
1163
1164
- /// The table sample method options
1165
1164
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1166
1165
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1167
1166
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1168
- pub enum TableSampleMethod {
1169
- Bernoulli ( TableSampleBernoulli ) ,
1170
- System ( TableSampleSystem ) ,
1171
- Bucket ( TableSampleBucket ) ,
1172
- Implicit ( TableSampleImplicit ) ,
1167
+ pub struct TableSample {
1168
+ pub modifier : TableSampleModifier ,
1169
+ pub name : Option < TableSampleMethod > ,
1170
+ pub quantity : Option < TableSampleQuantity > ,
1171
+ pub seed : Option < TableSampleSeed > ,
1172
+ pub bucket : Option < TableSampleBucket > ,
1173
+ pub offset : Option < Expr > ,
1173
1174
}
1174
1175
1175
- /// The table sample method names
1176
1176
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1177
1177
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1178
1178
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1179
- pub enum TableSampleMethodName {
1180
- Row ,
1181
- Bernoulli ,
1182
- System ,
1183
- Block ,
1179
+ pub enum TableSampleModifier {
1180
+ Sample ,
1181
+ TableSample ,
1184
1182
}
1185
1183
1186
- impl fmt:: Display for TableSampleMethodName {
1184
+ impl fmt:: Display for TableSampleModifier {
1187
1185
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1188
1186
match self {
1189
- TableSampleMethodName :: Bernoulli => write ! ( f, "BERNOULLI" ) ,
1190
- TableSampleMethodName :: Row => write ! ( f, "ROW" ) ,
1191
- TableSampleMethodName :: System => write ! ( f, "SYSTEM" ) ,
1192
- TableSampleMethodName :: Block => write ! ( f, "BLOCK" ) ,
1187
+ TableSampleModifier :: Sample => write ! ( f, "SAMPLE" ) ?,
1188
+ TableSampleModifier :: TableSample => write ! ( f, "TABLESAMPLE" ) ?,
1193
1189
}
1190
+ Ok ( ( ) )
1194
1191
}
1195
1192
}
1196
1193
1197
1194
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1198
1195
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1199
1196
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1200
- pub struct TableSampleBernoulli {
1201
- pub name : TableSampleMethodName ,
1202
- pub probability : Option < Value > ,
1203
- pub value : Option < Value > ,
1197
+ pub struct TableSampleQuantity {
1198
+ pub parenthesized : bool ,
1199
+ pub value : Expr ,
1204
1200
pub unit : Option < TableSampleUnit > ,
1205
1201
}
1206
1202
1207
- impl fmt:: Display for TableSampleBernoulli {
1203
+ impl fmt:: Display for TableSampleQuantity {
1208
1204
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1209
- write ! ( f , " {} (" , self . name ) ? ;
1210
- if let Some ( probability ) = & self . probability {
1211
- write ! ( f , "{})" , probability ) ? ;
1212
- } else if let Some ( value ) = & self . value {
1213
- write ! ( f , "{}" , value ) ? ;
1214
- if let Some ( unit ) = & self . unit {
1215
- write ! ( f , " {}" , unit ) ? ;
1216
- }
1205
+ if self . parenthesized {
1206
+ write ! ( f , "(" ) ? ;
1207
+ }
1208
+ write ! ( f , "{}" , self . value) ? ;
1209
+ if let Some ( unit ) = & self . unit {
1210
+ write ! ( f , " {}" , unit ) ? ;
1211
+ }
1212
+ if self . parenthesized {
1217
1213
write ! ( f, ")" ) ?;
1218
1214
}
1219
1215
Ok ( ( ) )
1220
1216
}
1221
1217
}
1222
1218
1219
+ /// The table sample method names
1223
1220
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1224
1221
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1225
1222
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1226
- pub struct TableSampleSystem {
1227
- pub name : TableSampleMethodName ,
1228
- pub probability : Value ,
1229
- pub seed : Option < TableSampleSeed > ,
1223
+ pub enum TableSampleMethod {
1224
+ Row ,
1225
+ Bernoulli ,
1226
+ System ,
1227
+ Block ,
1230
1228
}
1231
1229
1232
- impl fmt:: Display for TableSampleSystem {
1230
+ impl fmt:: Display for TableSampleMethod {
1233
1231
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1234
- write ! ( f, " {} ({})" , self . name, self . probability) ?;
1235
- if let Some ( seed) = & self . seed {
1236
- write ! ( f, " {} ({})" , seed. modifier, seed. value) ?;
1232
+ match self {
1233
+ TableSampleMethod :: Bernoulli => write ! ( f, "BERNOULLI" ) ,
1234
+ TableSampleMethod :: Row => write ! ( f, "ROW" ) ,
1235
+ TableSampleMethod :: System => write ! ( f, "SYSTEM" ) ,
1236
+ TableSampleMethod :: Block => write ! ( f, "BLOCK" ) ,
1237
1237
}
1238
- Ok ( ( ) )
1239
1238
}
1240
1239
}
1241
1240
@@ -1247,6 +1246,13 @@ pub struct TableSampleSeed {
1247
1246
pub value : Value ,
1248
1247
}
1249
1248
1249
+ impl fmt:: Display for TableSampleSeed {
1250
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1251
+ write ! ( f, "{} ({})" , self . modifier, self . value) ?;
1252
+ Ok ( ( ) )
1253
+ }
1254
+ }
1255
+
1250
1256
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1251
1257
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1252
1258
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -1299,41 +1305,23 @@ impl fmt::Display for TableSampleBucket {
1299
1305
Ok ( ( ) )
1300
1306
}
1301
1307
}
1302
-
1303
- #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1304
- #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1305
- #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1306
- pub struct TableSampleImplicit {
1307
- pub value : Value ,
1308
- pub unit : Option < TableSampleUnit > ,
1309
- }
1310
-
1311
- impl fmt:: Display for TableSampleImplicit {
1308
+ impl fmt:: Display for TableSample {
1312
1309
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1313
- write ! ( f, "{}" , self . value ) ?;
1314
- if let Some ( unit ) = & self . unit {
1315
- write ! ( f, " {}" , unit ) ?;
1310
+ write ! ( f, " {}" , self . modifier ) ?;
1311
+ if let Some ( name ) = & self . name {
1312
+ write ! ( f, " {}" , name ) ?;
1316
1313
}
1317
- Ok ( ( ) )
1318
- }
1319
- }
1320
-
1321
- impl fmt:: Display for TableSampleMethod {
1322
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1323
- write ! ( f, " TABLESAMPLE" ) ?;
1324
- match self {
1325
- TableSampleMethod :: Bernoulli ( sample) => {
1326
- write ! ( f, "{}" , sample) ?;
1327
- }
1328
- TableSampleMethod :: System ( sample) => {
1329
- write ! ( f, "{}" , sample) ?;
1330
- }
1331
- TableSampleMethod :: Bucket ( sample) => {
1332
- write ! ( f, " ({})" , sample) ?;
1333
- }
1334
- TableSampleMethod :: Implicit ( sample) => {
1335
- write ! ( f, " ({})" , sample) ?;
1336
- }
1314
+ if let Some ( quantity) = & self . quantity {
1315
+ write ! ( f, " {}" , quantity) ?;
1316
+ }
1317
+ if let Some ( seed) = & self . seed {
1318
+ write ! ( f, " {}" , seed) ?;
1319
+ }
1320
+ if let Some ( bucket) = & self . bucket {
1321
+ write ! ( f, " ({})" , bucket) ?;
1322
+ }
1323
+ if let Some ( offset) = & self . offset {
1324
+ write ! ( f, " OFFSET {}" , offset) ?;
1337
1325
}
1338
1326
Ok ( ( ) )
1339
1327
}
0 commit comments