SQL LIKE to Oracle NoSQL regex_like Converter #73
dario-vega
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
Oracle NoSQL Database does not support the standard SQL
LIKEoperator but instead usesregex_like()with a limited subset of regex features. This proposal introduces a Java utility to automatically convert SQLLIKEpatterns to Oracle NoSQL-compatibleregex_like()patterns.Problem Statement
When migrating SQL queries to Oracle NoSQL or working with both SQL and NoSQL databases, developers must manually convert
LIKEpatterns toregex_like()patterns. This is error-prone and time-consuming due to:%and_vs regex.*and..,*,\\escaping, and\\Q...\\Equoting.,*,[,]must be properly escaped or quotedProposed Solution
A Java converter utility that provides:
Core Features
Pattern Conversion: Converts SQL LIKE patterns to regex_like patterns
%Smith%→.*\\QSmith\\E.*J_hn→\\QJ\\E.\\Qhn\\E%.txt→.*\\Q.txt\\ETwo Quoting Styles:
\\Q...\\Efor literal sections (default)%**Houston**%→.*\\Q**Houston**\\E.*\\to escape each special character%**Houston**%→.*\\*\\*Houston\\*\\*.*WHERE Clause Conversion: Automatically converts entire WHERE clauses
name LIKE '%Smith%'regex_like(name, '.*\\QSmith\\E.*')Escaped Wildcard Support: Handles SQL escaped wildcards (
\_,\%)test\_user%→\\Qtest\\E\\Q_\\E\\Quser\\E.*API Design
Conversion Rules
%.*_.\%\\Q%\\Eor\\.\\*\_\\Q_\\Eor\\.\\Q...\\E.*[]Implementation
The complete implementation is available as a single Java class with:
Supported Oracle NoSQL regex_like Features
Oracle NoSQL regex_like supports only these metacharacters:
.(period): matches any single character except newline*(asterisk): zero or more occurrences of preceding element\\(double backslash): escape metacharacters (e.g.,\\.or\\*)\\Q...\\E: quote literal strings (e.g.,\\Q**Houston**\\E)Unsupported Features
The following standard regex features are NOT supported in Oracle NoSQL:
[abc],[^abc],[a-z]^,$+,?,{n},{n,m}(),|(?i)Use Cases
Testing
The implementation includes:
Example Output
Basic Patterns
Comparison Table
%Smith%.*\\QSmith\\E.*.*Smith.*%.txt.*\\Q.txt\\E.*\\.txt%**Houston**%.*\\Q**Houston**\\E.*.*\\*\\*Houston\\*\\*.*J_hn\\QJ\\E.\\Qhn\\EJ.hntest\_user%\\Qtest\\E\\Q_\\E\\Quser\\E.*test\\.user.*Complete Query Examples
Benefits
Code Availability
The complete Java implementation is available in this discussion. Key features:
LikeToRegexConverterInstallation & Usage
As a Utility Class
LikeToRegexConverter.javato your projectRunning the Demo
The demo will show:
Performance Considerations
Discussion
I'd love to hear feedback on:
Please share your thoughts, suggestions, and use cases!
Related Resources
Tags:
oracle-nosqlsqlregexquery-conversionmigrationjavaBeta Was this translation helpful? Give feedback.
All reactions