This example demonstrates how to use the regexp_* functions the full list of supported features and syntax can be found at https://docs.rs/regex/latest/regex/#syntax Supported flags can be found at https://docs.rs/regex/latest/regex/#grouping-and-flags
()
| 31 | /// Supported flags can be found at |
| 32 | /// https://docs.rs/regex/latest/regex/#grouping-and-flags |
| 33 | pub async fn regexp() -> Result<()> { |
| 34 | let ctx = SessionContext::new(); |
| 35 | let dataset = ExampleDataset::Regex; |
| 36 | |
| 37 | ctx.register_csv("examples", dataset.path_str()?, CsvReadOptions::new()) |
| 38 | .await?; |
| 39 | |
| 40 | // |
| 41 | // |
| 42 | //regexp_like examples |
| 43 | // |
| 44 | // |
| 45 | // regexp_like format is (regexp_like(text, regex[, flags]) |
| 46 | // |
| 47 | |
| 48 | // use sql and regexp_like function to test col 'values', against patterns in col 'patterns' without flags |
| 49 | let result = ctx |
| 50 | .sql("select regexp_like(values, patterns) from examples") |
| 51 | .await? |
| 52 | .collect() |
| 53 | .await?; |
| 54 | |
| 55 | assert_batches_eq!( |
| 56 | &[ |
| 57 | "+------------------------------------------------+", |
| 58 | "| regexp_like(examples.values,examples.patterns) |", |
| 59 | "+------------------------------------------------+", |
| 60 | "| true |", |
| 61 | "| true |", |
| 62 | "| false |", |
| 63 | "| false |", |
| 64 | "| false |", |
| 65 | "| false |", |
| 66 | "| true |", |
| 67 | "| true |", |
| 68 | "| true |", |
| 69 | "| true |", |
| 70 | "| true |", |
| 71 | "+------------------------------------------------+", |
| 72 | ], |
| 73 | &result |
| 74 | ); |
| 75 | |
| 76 | // use sql and regexp_like function to test col 'values', against patterns in col 'patterns' with flags |
| 77 | let result = ctx |
| 78 | .sql("select regexp_like(values, patterns, flags) from examples") |
| 79 | .await? |
| 80 | .collect() |
| 81 | .await?; |
| 82 | |
| 83 | assert_batches_eq!( |
| 84 | &[ |
| 85 | "+---------------------------------------------------------------+", |
| 86 | "| regexp_like(examples.values,examples.patterns,examples.flags) |", |
| 87 | "+---------------------------------------------------------------+", |
| 88 | "| true |", |
| 89 | "| true |", |
| 90 | "| true |", |