Adventures with Rust: Parsing with Pest

match glue_type {
"int" => Ok(DataType::Int32),
"boolean" => Ok(DataType::Boolean),
"bigint" => Ok(DataType::Int64),
"float" => Ok(DataType::Float32),
...
}
static ref DECIMAL_RE: Regex = Regex::new("^decimal\\((?P<precision>\\d+)\\s*,\\s*(?P<scale>\\d+)\\)$").unwrap();static ref ARRAY_RE: Regex = Regex::new("^array<(?P<array_type>.+)>$").unwrap();_ => {
if let Some(decimal_cg) = DECIMAL_RE.captures(glue_type) {
let precision = decimal_cg
.name("precision")
.unwrap()
.as_str()
.parse()
.unwrap();
let scale = decimal_cg.name("scale").unwrap().as_str().parse().unwrap();
Ok(DataType::Decimal(precision, scale))
} else if let Some(array_cg) = ARRAY_RE.captures(glue_type) {
let array_type = array_cg.name("array_type").unwrap().as_str();
let field = Self::map_to_arrow_field(glue_name, array_type)?;
Ok(DataType::List(Box::new(field)))
...
DataType = _{ SimpleType | ArrayType | MapType | StructType }
SimpleType = _{ TinyInt | SmallInt | Int | Boolean | BigInt | Float | Double | Binary | Date | Timestamp | String | Char | Varchar | Decimal }
TinyInt = { "tinyint" }
SmallInt = { "smallint" }
Int = { "int" | "integer" }
Decimal = { "decimal(" ~ number ~ "," ~ number ~ ")" }
ArrayType = { "array<" ~ DataType ~ ">" }
MapType = { "map<" ~ DataType ~ "," ~ DataType ~ ">" }
StructType = { "struct<" ~ structFields ~ ">" }
structFields = _{ structField ~ ("," ~ structField)* }
structField = { ident ~ ":" ~ DataType }

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tim Van Wassenhove

Tim Van Wassenhove

More from Medium

Origin DNS error |

Kubernetes new Release and Major changes

S72MQTT, a Coreflux Flux Asset

Hire Golang Developer with Think Future Technologies