我的任务是缩短大型SQL查询以进行记录。因此,我需要匹配这样的查询:
SELECT PersonID,
Name,
City,
MIN(ArriveDate),
MAX(LeaveDate)
FROM customertravel
WHERE PersonID IN (1, 2, 7)
GROUP BY PersonID,
Name,
City;
我的Regex代码是:
INSERT INTO analytics_events (person_id,other_person_id,location_id,location_name,date,action,type,info,created_at,updated_at) VALUES
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
(123, 456, 19, 'Sarasota', '2018-10-31 09:08:17.982', 'send', 'email', 'Subject: Check out this cat video', '2018-10-31 09:09:17.982', '2018-10-31 09:09:17.982'),
(321, 654, 89, 'Indianapolis', '2018-10-31 09:08:18.982', 'read', 'page', 'Title: You\'ll Never Believe What they said', '2018-10-31 09:09:19.982', '2018-10-31 09:09:19.982'),
... '9998 more rows')
不幸的是,这导致了此异常:
Pattern.compile("INSERT(.|\\n)*INTO(.|\\n)*VALUES(.|\\n)*", Pattern.CASE_INSENSITIVE);
我的目标是将该SQL文本转换为没有数据成分的内容,例如:
java.lang.StackOverflowError
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3774)
at java.util.regex.Pattern$Branch.match(Pattern.java:4604)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
at java.util.regex.Pattern$Loop.match(Pattern.java:4785)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717)
出于汇总查询时间统计的目的。