[ASTERIXDB-2305][FUN] replace() should not accept regular expressions
- user model changes: yes
- storage format changes: no
- interface changes: no
Details:
- replace() function was equivalent to regexp_replace(),
both were based on regular expressions
- this change makes replace() function operate on plain strings
- regexp_replace() continues to operate on regular expressions
Change-Id: Ic01db334c2ef0cab5834cc161ee4f212cf2cb105
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2440
Reviewed-by: Till Westmann <tillw@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.1.query.aql
similarity index 66%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.3.query.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.1.query.aql
index 16364fb..30b88fd 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.3.query.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.1.query.aql
@@ -16,14 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-use dataverse test;
-let $c1 := replace("abracadabra", "", null, null)
-let $c2 := replace("abracadabra", "bra", "XXX", "")
-let $c3 := replace(null,"hello world", "XxXx", "x")
-let $c4 := replace("abracadabra", "bra", "XXX", null)
-let $c5 := replace("abracadabra", null, "XXX", null)
-let $c6 := replace("abracadabra", "Bra", null, "i")
-let $c7 := replace("abracadabra", "Bra", "", "i")
-let $c8 := replace("abracadabra", "", "XXX", "")
+let $c1 := regexp-replace("abracadabra", "", null, null)
+let $c2 := regexp-replace("abracadabra", "bra", "XXX", "")
+let $c3 := regexp-replace(null,"hello world", "XxXx", "x")
+let $c4 := regexp-replace("abracadabra", "bra", "XXX", null)
+let $c5 := regexp-replace("abracadabra", null, "XXX", null)
+let $c6 := regexp-replace("abracadabra", "Bra", null, "i")
+let $c7 := regexp-replace("abracadabra", "Bra", "", "i")
+let $c8 := regexp-replace("abracadabra", "", "XXX", "")
return {"result1": $c1,"result2": $c2,"result3": $c3,"result4": $c4,"result5": $c5,"result6": $c6,"result7": $c7,"result8": $c8}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.2.query.aql
similarity index 83%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.3.query.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.2.query.aql
index 28a5276..fa5e6bd 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.3.query.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.2.query.aql
@@ -16,9 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-use dataverse test;
-let $c1 := replace("abracadabra", "a", "")
-let $c2 := replace("abracadabra", "a(.)", "a$1$1")
-let $c3 := replace("darted", "^(.*?)d(.*)$", "$1c$2")
+let $c1 := regexp-replace("abracadabra", "a", "")
+let $c2 := regexp-replace("abracadabra", "a(.)", "a$1$1")
+let $c3 := regexp-replace("darted", "^(.*?)d(.*)$", "$1c$2")
return {"result1": $c1, "result2": $c2, "result3": $c3}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.3.query.aql
similarity index 92%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.3.query.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.3.query.aql
index f722e54..87329ce 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.3.query.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.3.query.aql
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-use dataverse test;
-let $c1 := replace("abracadabra", "a.*a", "*")
+let $c1 := regexp-replace("abracadabra", "bra", "*")
return {"result1": $c1}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.4.query.aql
similarity index 92%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.3.query.aql
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.4.query.aql
index f722e54..61ad141 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.3.query.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.4.query.aql
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-use dataverse test;
-let $c1 := replace("abracadabra", "a.*a", "*")
+let $c1 := regexp-replace("abracadabra", "a.*a", "*")
return {"result1": $c1}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.5.query.aql
similarity index 81%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.3.query.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.5.query.aql
index 081f3f4..b475933 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.3.query.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/regexp_replace/regexp_replace.5.query.aql
@@ -16,9 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-use dataverse test;
-let $c1 := replace("abracadabra","Bra", "kkk" , "")
-let $c2 := replace("abracadabra","Bra", "kkk" ,"i")
-let $c3 := replace("helloworld","hello world", "kkk" , "x")
+let $c1 := regexp-replace("abracadabra","Bra", "kkk" , "")
+let $c2 := regexp-replace("abracadabra","Bra", "kkk" ,"i")
+let $c3 := regexp-replace("helloworld","hello world", "kkk" , "x")
return {"result1": $c1,"result2": $c2,"result3": $c3}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.1.ddl.aql
deleted file mode 100644
index d17ea60..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.1.ddl.aql
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.2.update.aql
deleted file mode 100644
index 042f3ce..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace1/replace1.2.update.aql
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.1.ddl.aql
deleted file mode 100644
index d17ea60..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.1.ddl.aql
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.2.update.aql
deleted file mode 100644
index 042f3ce..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.2.update.aql
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.3.query.aql
deleted file mode 100644
index 41ccd31..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace2/replace2.3.query.aql
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-use dataverse test;
-
-let $c1 := replace("abracadabra", "bra", "*")
-return {"result1": $c1}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.1.ddl.aql
deleted file mode 100644
index d17ea60..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.1.ddl.aql
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.2.update.aql
deleted file mode 100644
index 042f3ce..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.2.update.aql
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.1.ddl.aql
deleted file mode 100644
index d17ea60..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.1.ddl.aql
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.2.update.aql
deleted file mode 100644
index 042f3ce..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.2.update.aql
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.1.ddl.aql
deleted file mode 100644
index d17ea60..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.1.ddl.aql
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.2.update.aql
deleted file mode 100644
index 042f3ce..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/string/replace3/replace3.2.update.aql
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.1.query.sqlpp
index 819bb83..fbdf750 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.1.query.sqlpp
@@ -17,8 +17,6 @@
* under the License.
*/
-
-
{
'result1':REGEXP_REPLACE('abracadabra','',null,null),
'result2':REGEXP_REPLACE('abracadabra','bra','XXX',''),
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.2.query.sqlpp
similarity index 81%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.2.query.sqlpp
index 21479a2..a158d7f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.2.query.sqlpp
@@ -17,6 +17,8 @@
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
-
+{
+ 'result1':regexp_replace('abracadabra','a',''),
+ 'result2':regexp_replace('abracadabra','a(.)','a$1$1'),
+ 'result3':regexp_replace('darted','^(.*?)d(.*)$','$1c$2')
+};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.3.query.sqlpp
similarity index 92%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.3.query.sqlpp
index 21479a2..910e476 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.3.query.sqlpp
@@ -17,6 +17,6 @@
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
-
+{
+ 'result1':regexp_replace('abracadabra','bra','*')
+};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.4.query.sqlpp
similarity index 92%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.4.query.sqlpp
index 21479a2..b43481f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.4.query.sqlpp
@@ -17,6 +17,6 @@
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
-
+{
+ 'result1':regexp_replace('abracadabra','a.*a','*')
+};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.5.query.sqlpp
similarity index 80%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.5.query.sqlpp
index 21479a2..600abe0 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/regexp_replace/regexp_replace.5.query.sqlpp
@@ -17,6 +17,8 @@
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
-
+{
+ 'result1':regexp_replace('abracadabra','Bra','kkk',''),
+ 'result2':regexp_replace('abracadabra','Bra','kkk','i'),
+ 'result3':regexp_replace('helloworld','hello world','kkk','x')
+};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace/replace.1.query.sqlpp
similarity index 64%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.3.query.sqlpp
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace/replace.1.query.sqlpp
index e8d5e6f..e08be20 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.3.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace/replace.1.query.sqlpp
@@ -17,7 +17,17 @@
* under the License.
*/
-use test;
-
-
-{'result1':test.replace('abracadabra','bra','*')};
+select value t from
+[
+ [ 0, is_missing(replace("", null, missing)) ],
+ [ 1, is_null(replace("", null, null)) ],
+ [ 2, is_null(replace("", "", null)) ],
+ [ 3, replace("", "", "") ],
+ [ 4, replace("", "", "a") ],
+ [ 5, replace("a", "a", "") ],
+ [ 6, replace("aaa", "a", "b") ],
+ [ 7, replace("ab_ba_ab", "ab", "ba") ],
+ [ 8, replace("_ab_ba_ab_", "ab", "xyz") ],
+ [ 9, replace("abracadabra_abracadabra_xyz","bra","*BRA*") ]
+] t
+order by t[0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace/replace.2.query.sqlpp
similarity index 89%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace/replace.2.query.sqlpp
index 21479a2..61414fb 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace/replace.2.query.sqlpp
@@ -17,6 +17,6 @@
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
-
+select value replace(t, "ab", "ba")
+from ["", "aaa", "ab", "c_ab_ba_ab_ba_ab_c"] t
+order by t
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.2.update.sqlpp
deleted file mode 100644
index bd244d0..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.2.update.sqlpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.3.query.sqlpp
deleted file mode 100644
index 93cb554..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.3.query.sqlpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-use test;
-
-
-{'result1':test.replace('abracadabra','a',''),'result2':test.replace('abracadabra','a(.)','a$1$1'),'result3':test.replace('darted','^(.*?)d(.*)$','$1c$2')};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.1.ddl.sqlpp
deleted file mode 100644
index 21479a2..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.1.ddl.sqlpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.2.update.sqlpp
deleted file mode 100644
index bd244d0..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace2/replace2.2.update.sqlpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.1.ddl.sqlpp
deleted file mode 100644
index 21479a2..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.1.ddl.sqlpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.2.update.sqlpp
deleted file mode 100644
index bd244d0..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.2.update.sqlpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.3.query.sqlpp
deleted file mode 100644
index 25e5559..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace21/replace21.3.query.sqlpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-use test;
-
-
-{'result1':test.replace('abracadabra','Bra','kkk',''),'result2':test.replace('abracadabra','Bra','kkk','i'),'result3':test.replace('helloworld','hello world','kkk','x')};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.1.ddl.sqlpp
deleted file mode 100644
index 21479a2..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.1.ddl.sqlpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.2.update.sqlpp
deleted file mode 100644
index bd244d0..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.2.update.sqlpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.3.query.sqlpp
deleted file mode 100644
index 4772d91..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace22/replace22.3.query.sqlpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-use test;
-
-
-{'result1':test.replace('abracadabra','',null,null),'result2':test.replace('abracadabra','bra','XXX',''),'result3':test.replace(null,'hello world','XxXx','x'),'result4':test.replace('abracadabra','bra','XXX',null),'result5':test.replace('abracadabra',null,'XXX',null),'result6':test.replace('abracadabra','Bra',null,'i'),'result7':test.replace('abracadabra','Bra','','i'),'result8':test.replace('abracadabra','','XXX','')};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.1.ddl.sqlpp
deleted file mode 100644
index 21479a2..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.1.ddl.sqlpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-drop dataverse test if exists;
-create dataverse test;
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.2.update.sqlpp
deleted file mode 100644
index bd244d0..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.2.update.sqlpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.3.query.sqlpp
deleted file mode 100644
index a0eb4b4..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace3/replace3.3.query.sqlpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-use test;
-
-
-{'result1':test.replace('abracadabra','a.*a','*')};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace_with_limit/replace_with_limit.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace_with_limit/replace_with_limit.1.query.sqlpp
new file mode 100644
index 0000000..3c33e49
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace_with_limit/replace_with_limit.1.query.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+select value t from
+[
+ [ 0, is_missing(replace("", null, missing, 1)) ],
+ [ 1, is_null(replace("", null, null, 1)) ],
+ [ 2, is_null(replace("", "", null, 1)) ],
+ [ 3, replace("", "", "", 1) ],
+ [ 4, replace("", "", "a", 1) ],
+ [ 5, replace("a", "a", "", tinyint("1")) ],
+ [ 6, replace("aaa", "a", "b", smallint("2")) ],
+ [ 7, replace("ab_ba_ab", "ab", "ba", integer("100")) ],
+ [ 8, replace("_ab_ba_ab_ab_ab_", "ab", "xyz", bigint("4")) ],
+ [ 9, replace("abracadabra_abracadabra_xyz","bra","*BRA*", 3) ],
+ [ 10, replace("ab_ba_ab", "ab", "ba", 0) ],
+ [ 11, replace("ab_ba_ab", "ab", "ba", -100) ]
+] t
+order by t[0]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace_with_limit/replace_with_limit.2.query.sqlpp
similarity index 88%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace_with_limit/replace_with_limit.2.query.sqlpp
index 21479a2..073d033 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace1/replace1.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/replace_with_limit/replace_with_limit.2.query.sqlpp
@@ -17,6 +17,6 @@
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
-
+select value replace(t, "ab", "ba", 2)
+from ["", "aaa", "ab", "c_ab_ba_ab_ba_ab_c"] t
+order by t
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace22/replace22.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.1.adm
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace22/replace22.1.adm
rename to asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.1.adm
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace1/replace1.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.2.adm
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace1/replace1.1.adm
rename to asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.2.adm
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace2/replace2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.3.adm
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace2/replace2.1.adm
rename to asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.3.adm
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace3/replace3.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.4.adm
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace3/replace3.1.adm
rename to asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.4.adm
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace21/replace21.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.5.adm
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace21/replace21.1.adm
rename to asterixdb/asterix-app/src/test/resources/runtimets/results/string/regexp_replace/regexp_replace.5.adm
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace/replace.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace/replace.1.adm
new file mode 100644
index 0000000..a7e9a61
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace/replace.1.adm
@@ -0,0 +1,10 @@
+[ 0, true ]
+[ 1, true ]
+[ 2, true ]
+[ 3, "" ]
+[ 4, "a" ]
+[ 5, "" ]
+[ 6, "bbb" ]
+[ 7, "ba_ba_ba" ]
+[ 8, "_xyz_ba_xyz_" ]
+[ 9, "a*BRA*cada*BRA*_a*BRA*cada*BRA*_xyz" ]
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace/replace.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace/replace.2.adm
new file mode 100644
index 0000000..c911519
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace/replace.2.adm
@@ -0,0 +1,4 @@
+""
+"aaa"
+"ba"
+"c_ba_ba_ba_ba_ba_c"
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace_with_limit/replace_with_limit.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace_with_limit/replace_with_limit.1.adm
new file mode 100644
index 0000000..1e7020e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace_with_limit/replace_with_limit.1.adm
@@ -0,0 +1,12 @@
+[ 0, true ]
+[ 1, true ]
+[ 2, true ]
+[ 3, "" ]
+[ 4, "a" ]
+[ 5, "" ]
+[ 6, "bba" ]
+[ 7, "ba_ba_ba" ]
+[ 8, "_xyz_ba_xyz_xyz_xyz_" ]
+[ 9, "a*BRA*cada*BRA*_a*BRA*cadabra_xyz" ]
+[ 10, "ab_ba_ab" ]
+[ 11, "ab_ba_ab" ]
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace_with_limit/replace_with_limit.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace_with_limit/replace_with_limit.2.adm
new file mode 100644
index 0000000..5831b1b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/string/replace_with_limit/replace_with_limit.2.adm
@@ -0,0 +1,4 @@
+""
+"aaa"
+"ba"
+"c_ba_ba_ba_ba_ab_c"
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index 15828be..50ea7e3 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -5443,28 +5443,8 @@
</compilation-unit>
</test-case>
<test-case FilePath="string">
- <compilation-unit name="replace1">
- <output-dir compare="Text">replace1</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace2">
- <output-dir compare="Text">replace2</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace21">
- <output-dir compare="Text">replace21</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace22">
- <output-dir compare="Text">replace22</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace3">
- <output-dir compare="Text">replace3</output-dir>
+ <compilation-unit name="regexp_replace">
+ <output-dir compare="Text">regexp_replace</output-dir>
</compilation-unit>
</test-case>
<test-case FilePath="string">
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 6bb1886..7d064a5 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -6201,33 +6201,18 @@
</compilation-unit>
</test-case>
<test-case FilePath="string">
+ <compilation-unit name="replace">
+ <output-dir compare="Text">replace</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="string">
+ <compilation-unit name="replace_with_limit">
+ <output-dir compare="Text">replace_with_limit</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="string">
<compilation-unit name="regexp_replace">
- <output-dir compare="Text">replace22</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace1">
- <output-dir compare="Text">replace1</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace2">
- <output-dir compare="Text">replace2</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace21">
- <output-dir compare="Text">replace21</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace22">
- <output-dir compare="Text">replace22</output-dir>
- </compilation-unit>
- </test-case>
- <test-case FilePath="string">
- <compilation-unit name="replace3">
- <output-dir compare="Text">replace3</output-dir>
+ <output-dir compare="Text">regexp_replace</output-dir>
</compilation-unit>
</test-case>
<test-case FilePath="string">
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/2_string_common.md b/asterixdb/asterix-doc/src/main/markdown/builtins/2_string_common.md
index 1f56c4c..0e548a7 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/2_string_common.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/2_string_common.md
@@ -332,7 +332,7 @@
* Checks whether the string `string` matches the given
regular expression pattern `string_pattern` (a Java regular expression pattern),
- and replace the matched pattern `string_pattern` with the new pattern `string_replacement`.
+ and replaces the matched pattern `string_pattern` with the new pattern `string_replacement`.
* Arguments:
* `string` : a `string` that might contain the pattern,
* `string_pattern` : a pattern `string` to be matched,
@@ -381,6 +381,38 @@
"testtesttest"
+### replace ###
+ * Syntax:
+
+ replace(string, search_string, replacement_string[, limit])
+
+ * Finds occurrences of the given substring `search_string` in the input string `string`
+ and replaces them with the new substring `replacement_string`.
+ * Arguments:
+ * `string` : an input `string`,
+ * `search_string` : a `string` substring to be searched for,
+ * `replacement_string` : a `string` to be used as the replacement,
+ * `limit` : (Optional) an `integer` - maximum number of occurrences to be replaced.
+ If not specified then all occurrences will be replaced
+ * Return Value:
+ * Returns a `string` that is obtained after the replacements,
+ * `missing` if any argument is a `missing` value,
+ * any other non-string input value or non-integer `limit` will cause a type error,
+ * `null` if any argument is a `null` value but no argument is a `missing` value.
+
+ * Example:
+
+ {
+ "v1": replace(" like x-phone the voicemail_service is awesome", " like x-phone", "like product-a"),
+ "v2": replace("x-phone and x-phone", "x-phone", "product-a", 1)
+ };
+
+ * The expected result is:
+
+ {
+ "v1": "like product-a the voicemail_service is awesome",
+ "v2": "product-a and x-phone"
+ }
### rtrim ###
* Syntax:
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
index 0646224..2aaf08f 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
@@ -39,7 +39,6 @@
FUNCTION_NAME_MAP.put("upper", "uppercase"); // upper, internal: uppercase
FUNCTION_NAME_MAP.put("title", "initcap"); // title, internal: initcap
FUNCTION_NAME_MAP.put("regexp_contains", "matches"); // regexp_contains, internal: matches
- FUNCTION_NAME_MAP.put("regexp_replace", "replace"); //regexp_replace, internal: replace
FUNCTION_NAME_MAP.put("power", "caret"); //pow, internal: caret
FUNCTION_NAME_MAP.put("int", "integer"); // int, internal: integer
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index 3e3cf43..92617ee 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -287,6 +287,10 @@
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "regexp-position", 2);
public static final FunctionIdentifier STRING_REGEXP_POSITION_WITH_FLAG =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "regexp-position", 3);
+ public static final FunctionIdentifier STRING_REGEXP_REPLACE =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "regexp-replace", 3);
+ public static final FunctionIdentifier STRING_REGEXP_REPLACE_WITH_FLAG =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "regexp-replace", 4);
public static final FunctionIdentifier STRING_LOWERCASE =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "lowercase", 1);
public static final FunctionIdentifier STRING_UPPERCASE =
@@ -309,7 +313,7 @@
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "position", 2);
public static final FunctionIdentifier STRING_REPLACE =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "replace", 3);
- public static final FunctionIdentifier STRING_REPLACE_WITH_FLAG =
+ public static final FunctionIdentifier STRING_REPLACE_WITH_LIMIT =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "replace", 4);
public static final FunctionIdentifier STRING_LENGTH =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "string-length", 1);
@@ -1043,8 +1047,10 @@
addFunction(STRING_REGEXP_LIKE_WITH_FLAG, StringBooleanTypeComputer.INSTANCE, true);
addFunction(STRING_REGEXP_POSITION, StringInt32TypeComputer.INSTANCE, true);
addFunction(STRING_REGEXP_POSITION_WITH_FLAG, StringInt32TypeComputer.INSTANCE, true);
+ addFunction(STRING_REGEXP_REPLACE, StringStringTypeComputer.INSTANCE, true);
+ addFunction(STRING_REGEXP_REPLACE_WITH_FLAG, StringStringTypeComputer.INSTANCE, true);
addFunction(STRING_REPLACE, StringStringTypeComputer.INSTANCE, true);
- addFunction(STRING_REPLACE_WITH_FLAG, StringStringTypeComputer.INSTANCE, true);
+ addFunction(STRING_REPLACE_WITH_LIMIT, StringIntToStringTypeComputer.INSTANCE_TRIPLE_STRING, true);
addFunction(SUBSTRING_BEFORE, StringStringTypeComputer.INSTANCE, true);
addFunction(SUBSTRING_AFTER, StringStringTypeComputer.INSTANCE, true);
addPrivateFunction(STRING_EQUAL, StringBooleanTypeComputer.INSTANCE, true);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringIntToStringTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringIntToStringTypeComputer.java
index 5b3cf54..e29b6ec 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringIntToStringTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringIntToStringTypeComputer.java
@@ -27,15 +27,24 @@
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
public class StringIntToStringTypeComputer extends AbstractResultTypeComputer {
- public static final StringIntToStringTypeComputer INSTANCE = new StringIntToStringTypeComputer();
+ public static final StringIntToStringTypeComputer INSTANCE = new StringIntToStringTypeComputer(1);
+
+ public static final StringIntToStringTypeComputer INSTANCE_TRIPLE_STRING = new StringIntToStringTypeComputer(3);
+
+ private final int stringArgCount;
+
+ public StringIntToStringTypeComputer(int stringArgCount) {
+ this.stringArgCount = stringArgCount;
+ }
@Override
public void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
ATypeTag tag = type.getTypeTag();
- if (argIndex == 0 && tag != ATypeTag.STRING) {
- throw new TypeMismatchException(funcName, argIndex, tag, ATypeTag.STRING);
- }
- if (argIndex == 1) {
+ if (argIndex < stringArgCount) {
+ if (tag != ATypeTag.STRING) {
+ throw new TypeMismatchException(funcName, argIndex, tag, ATypeTag.STRING);
+ }
+ } else {
switch (tag) {
case TINYINT:
case SMALLINT:
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractStringStringStringIntEval.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractStringStringStringIntEval.java
new file mode 100644
index 0000000..89bba67
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractStringStringStringIntEval.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public abstract class AbstractStringStringStringIntEval implements IScalarEvaluator {
+ // Argument evaluators.
+ private IScalarEvaluator eval0;
+ private IScalarEvaluator eval1;
+ private IScalarEvaluator eval2;
+ private IScalarEvaluator eval3;
+
+ // Argument pointables.
+ final IPointable argPtrFirst = new VoidPointable();
+ final IPointable argPtrSecond = new VoidPointable();
+ final IPointable argPtrThird = new VoidPointable();
+ final IPointable argPtrFourth = new VoidPointable();
+ private final UTF8StringPointable strPtr1st = new UTF8StringPointable();
+ private final UTF8StringPointable strPtr2nd = new UTF8StringPointable();
+ private final UTF8StringPointable strPtr3rd = new UTF8StringPointable();
+
+ // For outputting results.
+ ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+ DataOutput dout = resultStorage.getDataOutput();
+
+ // Function ID, for error reporting.
+ protected final FunctionIdentifier funcID;
+
+ AbstractStringStringStringIntEval(IHyracksTaskContext context, IScalarEvaluatorFactory eval0,
+ IScalarEvaluatorFactory eval1, IScalarEvaluatorFactory eval2, IScalarEvaluatorFactory eval3,
+ FunctionIdentifier funcID) throws HyracksDataException {
+ this.eval0 = eval0.createScalarEvaluator(context);
+ this.eval1 = eval1.createScalarEvaluator(context);
+ this.eval2 = eval2.createScalarEvaluator(context);
+ this.eval3 = eval3.createScalarEvaluator(context);
+ this.funcID = funcID;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+ // Gets the first argument.
+ eval0.evaluate(tuple, argPtrFirst);
+ byte[] bytes0 = argPtrFirst.getByteArray();
+ int start0 = argPtrFirst.getStartOffset();
+ int len0 = argPtrFirst.getLength();
+
+ // Gets the second argument.
+ eval1.evaluate(tuple, argPtrSecond);
+ byte[] bytes1 = argPtrSecond.getByteArray();
+ int start1 = argPtrSecond.getStartOffset();
+ int len1 = argPtrSecond.getLength();
+
+ // Gets the third argument.
+ eval2.evaluate(tuple, argPtrThird);
+ byte[] bytes2 = argPtrThird.getByteArray();
+ int start2 = argPtrThird.getStartOffset();
+ int len2 = argPtrThird.getLength();
+
+ // Gets the fourth argument.
+ eval3.evaluate(tuple, argPtrFourth);
+ byte[] bytes3 = argPtrFourth.getByteArray();
+ int start3 = argPtrFourth.getStartOffset();
+
+ // Type check.
+ if (bytes0[start0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+ throw new TypeMismatchException(funcID, 0, bytes0[start0], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
+ }
+ if (bytes1[start1] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+ throw new TypeMismatchException(funcID, 1, bytes1[start1], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
+ }
+ if (bytes2[start2] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+ throw new TypeMismatchException(funcID, 2, bytes2[start2], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
+ }
+ if (bytes3[start3] != ATypeTag.SERIALIZED_INT8_TYPE_TAG && bytes3[start3] != ATypeTag.SERIALIZED_INT16_TYPE_TAG
+ && bytes3[start3] != ATypeTag.SERIALIZED_INT32_TYPE_TAG
+ && bytes3[start3] != ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
+ throw new TypeMismatchException(funcID, 3, bytes3[start3], ATypeTag.SERIALIZED_INT8_TYPE_TAG,
+ ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG,
+ ATypeTag.SERIALIZED_INT64_TYPE_TAG);
+ }
+
+ // Sets argument UTF8Pointables.
+ strPtr1st.set(bytes0, start0 + 1, len0 - 1);
+ strPtr2nd.set(bytes1, start1 + 1, len1 - 1);
+ strPtr3rd.set(bytes2, start2 + 1, len2 - 1);
+
+ long int4th = ATypeHierarchy.getLongValue(funcID.getName(), 3, bytes3, start3);
+
+ // Resets the output storage.
+ resultStorage.reset();
+ // The actual processing.
+ process(strPtr1st, strPtr2nd, strPtr3rd, int4th, result);
+ }
+
+ /**
+ * The actual processing of a string function.
+ *
+ * @param first
+ * , the first argument.
+ * @param second
+ * , the second argument.
+ * @param third
+ * , the third argument.
+ * @param fourth
+ * , the fourth argument.
+ * @param resultPointable
+ * , the result.
+ * @throws HyracksDataException
+ */
+ protected abstract void process(UTF8StringPointable first, UTF8StringPointable second, UTF8StringPointable third,
+ long fourth, IPointable resultPointable) throws HyracksDataException;
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
index 830f2ff..b2da86d 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
@@ -18,8 +18,6 @@
*/
package org.apache.asterix.runtime.evaluators.functions;
-import java.io.IOException;
-
import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
import org.apache.asterix.om.base.ABoolean;
import org.apache.asterix.om.types.BuiltinType;
@@ -46,7 +44,7 @@
@SuppressWarnings("unchecked")
@Override
protected void process(UTF8StringPointable first, UTF8StringPointable second, UTF8StringPointable thrid,
- IPointable result) throws IOException {
+ IPointable result) throws HyracksDataException {
ABoolean res = compute(first, second, thrid) ? ABoolean.TRUE : ABoolean.FALSE;
boolSerde.serialize(res, dout);
result.set(resultStorage);
@@ -62,9 +60,8 @@
* @param third
* , the second input argument.
* @return a boolean value.
- * @throws IOException
+ * @throws HyracksDataException
*/
protected abstract boolean compute(UTF8StringPointable first, UTF8StringPointable second, UTF8StringPointable third)
- throws IOException;
-
+ throws HyracksDataException;
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringEval.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringEval.java
index d4a9329..26563af 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringEval.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringEval.java
@@ -20,7 +20,6 @@
package org.apache.asterix.runtime.evaluators.functions;
import java.io.DataOutput;
-import java.io.IOException;
import org.apache.asterix.runtime.exceptions.TypeMismatchException;
import org.apache.asterix.om.types.ATypeTag;
@@ -43,9 +42,9 @@
private IScalarEvaluator eval2;
// Argument pointables.
- private IPointable argPtrFirst = new VoidPointable();
- private IPointable argPtrSecond = new VoidPointable();
- private IPointable argPtrThird = new VoidPointable();
+ final IPointable argPtrFirst = new VoidPointable();
+ final IPointable argPtrSecond = new VoidPointable();
+ final IPointable argPtrThird = new VoidPointable();
private final UTF8StringPointable strPtr1st = new UTF8StringPointable();
private final UTF8StringPointable strPtr2nd = new UTF8StringPointable();
private final UTF8StringPointable strPtr3rd = new UTF8StringPointable();
@@ -55,7 +54,7 @@
DataOutput dout = resultStorage.getDataOutput();
// Function ID, for error reporting.
- private final FunctionIdentifier funcID;
+ protected final FunctionIdentifier funcID;
AbstractTripleStringEval(IHyracksTaskContext context, IScalarEvaluatorFactory eval0, IScalarEvaluatorFactory eval1,
IScalarEvaluatorFactory eval2, FunctionIdentifier funcID) throws HyracksDataException {
@@ -87,7 +86,6 @@
int len2 = argPtrThird.getLength();
// Type check.
- // Type check.
if (bytes0[start0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(funcID, 0, bytes0[start0], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
@@ -106,11 +104,7 @@
// Resets the output storage.
resultStorage.reset();
// The actual processing.
- try {
- process(strPtr1st, strPtr2nd, strPtr3rd, result);
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
+ process(strPtr1st, strPtr2nd, strPtr3rd, result);
}
/**
@@ -121,12 +115,11 @@
* @param second
* , the second argument.
* @param third
- * , the second argument.
+ * , the third argument.
* @param resultPointable
* , the result.
- * @throws IOException
+ * @throws HyracksDataException
*/
protected abstract void process(UTF8StringPointable first, UTF8StringPointable second, UTF8StringPointable third,
- IPointable resultPointable) throws IOException;
-
+ IPointable resultPointable) throws HyracksDataException;
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringIntEval.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringIntEval.java
index 7f0076b..1ee6c8b 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringIntEval.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringIntEval.java
@@ -19,8 +19,6 @@
package org.apache.asterix.runtime.evaluators.functions;
-import java.io.IOException;
-
import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
import org.apache.asterix.om.base.AMutableInt32;
import org.apache.asterix.om.types.BuiltinType;
@@ -48,7 +46,7 @@
@SuppressWarnings("unchecked")
@Override
protected void process(UTF8StringPointable first, UTF8StringPointable second, UTF8StringPointable thrid,
- IPointable result) throws IOException {
+ IPointable result) throws HyracksDataException {
resultValue.setValue(compute(first, second, thrid));
intSerde.serialize(resultValue, dout);
result.set(resultStorage);
@@ -64,8 +62,8 @@
* @param third
* , the second input argument.
* @return an integer value.
- * @throws IOException
+ * @throws HyracksDataException
*/
protected abstract int compute(UTF8StringPointable first, UTF8StringPointable second, UTF8StringPointable third)
- throws IOException;
+ throws HyracksDataException;
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
index 48ef5f7..3c73b36 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
@@ -18,8 +18,6 @@
*/
package org.apache.asterix.runtime.evaluators.functions;
-import java.io.IOException;
-
import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
import org.apache.asterix.om.base.AMutableString;
import org.apache.asterix.om.types.BuiltinType;
@@ -47,7 +45,7 @@
@SuppressWarnings("unchecked")
@Override
protected void process(UTF8StringPointable first, UTF8StringPointable second, UTF8StringPointable thrid,
- IPointable result) throws IOException {
+ IPointable result) throws HyracksDataException {
resultValue.setValue(compute(first, second, thrid));
stringSerde.serialize(resultValue, dout);
result.set(resultStorage);
@@ -63,8 +61,8 @@
* @param third
* , the second input argument.
* @return a string value.
- * @throws IOException
+ * @throws HyracksDataException
*/
protected abstract String compute(UTF8StringPointable first, UTF8StringPointable second, UTF8StringPointable third)
- throws IOException;
+ throws HyracksDataException;
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpContainsWithFlagDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpContainsWithFlagDescriptor.java
index 44013e7..a5a79d9 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpContainsWithFlagDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpContainsWithFlagDescriptor.java
@@ -22,8 +22,6 @@
*/
package org.apache.asterix.runtime.evaluators.functions;
-import java.io.IOException;
-
import org.apache.asterix.om.functions.BuiltinFunctions;
import org.apache.asterix.om.functions.IFunctionDescriptor;
import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -59,7 +57,7 @@
@Override
protected boolean compute(UTF8StringPointable srcPtr, UTF8StringPointable patternPtr,
- UTF8StringPointable flagPtr) throws IOException {
+ UTF8StringPointable flagPtr) {
matcher.build(srcPtr, patternPtr, flagPtr);
return matcher.find();
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpLikeWithFlagDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpLikeWithFlagDescriptor.java
index 83971a0..635b4a6 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpLikeWithFlagDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpLikeWithFlagDescriptor.java
@@ -19,8 +19,6 @@
package org.apache.asterix.runtime.evaluators.functions;
-import java.io.IOException;
-
import org.apache.asterix.om.functions.BuiltinFunctions;
import org.apache.asterix.om.functions.IFunctionDescriptor;
import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -56,7 +54,7 @@
@Override
protected boolean compute(UTF8StringPointable srcPtr, UTF8StringPointable patternPtr,
- UTF8StringPointable flagPtr) throws IOException {
+ UTF8StringPointable flagPtr) {
matcher.build(srcPtr, patternPtr, flagPtr);
return matcher.matches();
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpPositionWithFlagDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpPositionWithFlagDescriptor.java
index 16d428f..0d910be 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpPositionWithFlagDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpPositionWithFlagDescriptor.java
@@ -19,8 +19,6 @@
package org.apache.asterix.runtime.evaluators.functions;
-import java.io.IOException;
-
import org.apache.asterix.om.functions.BuiltinFunctions;
import org.apache.asterix.om.functions.IFunctionDescriptor;
import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpReplaceDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpReplaceDescriptor.java
index fb2e2da..a1ea169 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpReplaceDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpReplaceDescriptor.java
@@ -55,7 +55,7 @@
@Override
protected String compute(UTF8StringPointable srcPtr, UTF8StringPointable patternPtr,
- UTF8StringPointable replacePtr) throws IOException {
+ UTF8StringPointable replacePtr) {
matcher.build(srcPtr, patternPtr);
return matcher.replace(replacePtr);
}
@@ -66,6 +66,6 @@
@Override
public FunctionIdentifier getIdentifier() {
- return BuiltinFunctions.STRING_REPLACE;
+ return BuiltinFunctions.STRING_REGEXP_REPLACE;
}
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpReplaceWithFlagsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpReplaceWithFlagsDescriptor.java
index 71383fc..f938c24 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpReplaceWithFlagsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringRegExpReplaceWithFlagsDescriptor.java
@@ -66,6 +66,6 @@
@Override
public FunctionIdentifier getIdentifier() {
- return BuiltinFunctions.STRING_REPLACE_WITH_FLAG;
+ return BuiltinFunctions.STRING_REGEXP_REPLACE_WITH_FLAG;
}
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
new file mode 100644
index 0000000..098d98f
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.utils.StringReplacer;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class StringReplaceDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new StringReplaceDescriptor();
+ }
+ };
+
+ @Override
+ public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+ return new IScalarEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
+ return new AbstractTripleStringEval(ctx, args[0], args[1], args[2], getIdentifier()) {
+
+ final StringReplacer replacer = new StringReplacer();
+
+ @Override
+ protected void process(UTF8StringPointable first, UTF8StringPointable second,
+ UTF8StringPointable third, IPointable resultPointable) throws HyracksDataException {
+ if (replacer.findAndReplace(first, second, third, Integer.MAX_VALUE)) {
+ replacer.assignResult(resultPointable);
+ } else {
+ resultPointable.set(argPtrFirst);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.STRING_REPLACE;
+ }
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithLimitDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithLimitDescriptor.java
new file mode 100644
index 0000000..fcd8218
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithLimitDescriptor.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.utils.StringReplacer;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class StringReplaceWithLimitDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new StringReplaceWithLimitDescriptor();
+ }
+ };
+
+ @Override
+ public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+ return new IScalarEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
+ return new AbstractStringStringStringIntEval(ctx, args[0], args[1], args[2], args[3], getIdentifier()) {
+
+ final StringReplacer replacer = new StringReplacer();
+
+ @Override
+ protected void process(UTF8StringPointable first, UTF8StringPointable second,
+ UTF8StringPointable third, long fourth, IPointable resultPointable)
+ throws HyracksDataException {
+ if (replacer.findAndReplace(first, second, third, (int) fourth)) {
+ replacer.assignResult(resultPointable);
+ } else {
+ resultPointable.set(argPtrFirst);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.STRING_REPLACE_WITH_LIMIT;
+ }
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/utils/StringReplacer.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/utils/StringReplacer.java
new file mode 100644
index 0000000..4e7e2f7
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/utils/StringReplacer.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.utils;
+
+import java.io.IOException;
+
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.util.GrowableArray;
+import org.apache.hyracks.data.std.util.UTF8StringBuilder;
+
+/**
+ * A wrapper for string replace methods.
+ */
+public final class StringReplacer {
+ // For outputting the result.
+ private final UTF8StringBuilder resultBuilder = new UTF8StringBuilder();
+ private final GrowableArray resultArray = new GrowableArray();
+ private final int resultArrayInitLength;
+
+ public StringReplacer() throws HyracksDataException {
+ try {
+ resultArray.getDataOutput().writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
+ resultArrayInitLength = resultArray.getLength();
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ }
+
+ public boolean findAndReplace(UTF8StringPointable input, UTF8StringPointable search, UTF8StringPointable replace,
+ int limit) throws HyracksDataException {
+ try {
+ resultArray.setSize(resultArrayInitLength);
+ return input.findAndReplace(search, replace, limit, resultBuilder, resultArray);
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ }
+
+ public void assignResult(IPointable resultPointable) {
+ resultPointable.set(resultArray.getByteArray(), 0, resultArray.getLength());
+ }
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
index b94f55e..df09ca6 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
@@ -243,6 +243,8 @@
import org.apache.asterix.runtime.evaluators.functions.StringRegExpReplaceDescriptor;
import org.apache.asterix.runtime.evaluators.functions.StringRegExpReplaceWithFlagsDescriptor;
import org.apache.asterix.runtime.evaluators.functions.StringRepeatDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.StringReplaceDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.StringReplaceWithLimitDescriptor;
import org.apache.asterix.runtime.evaluators.functions.StringSplitDescriptor;
import org.apache.asterix.runtime.evaluators.functions.StringStartsWithDescriptor;
import org.apache.asterix.runtime.evaluators.functions.StringToCodePointDescriptor;
@@ -571,6 +573,8 @@
fc.addGenerated(StringRTrim2Descriptor.FACTORY);
fc.addGenerated(StringPositionDescriptor.FACTORY);
fc.addGenerated(StringRepeatDescriptor.FACTORY);
+ fc.addGenerated(StringReplaceDescriptor.FACTORY);
+ fc.addGenerated(StringReplaceWithLimitDescriptor.FACTORY);
fc.addGenerated(StringSplitDescriptor.FACTORY);
// Constructors
diff --git a/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java b/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java
index 86a6f9c..8fdcd83 100644
--- a/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java
+++ b/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java
@@ -19,7 +19,8 @@
package org.apache.hyracks.data.std.primitive;
import java.io.IOException;
-import java.nio.charset.Charset;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import org.apache.commons.lang3.CharSet;
import org.apache.hyracks.api.dataflow.value.ITypeTraits;
@@ -161,7 +162,11 @@
@Override
public String toString() {
- return new String(this.bytes, this.getCharStartOffset(), this.getUTF8Length(), Charset.forName("UTF-8"));
+ try {
+ return new String(bytes, getCharStartOffset(), getUTF8Length(), StandardCharsets.UTF_8.name());
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException(e);
+ }
}
/****
@@ -218,7 +223,7 @@
char ch2 = pattern.charAt(pttnStart + c2);
if (ch1 != ch2) {
- if (!ignoreCase || ignoreCase && Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
+ if (!ignoreCase || Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
break;
}
}
@@ -261,7 +266,7 @@
char ch1 = src.charAt(s1Start + c1);
char ch2 = pattern.charAt(s2Start + c2);
if (ch1 != ch2) {
- if (!ignoreCase || ignoreCase && Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
+ if (!ignoreCase || Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
break;
}
}
@@ -292,7 +297,7 @@
char ch2 = pattern.charAt(s2Start + c2);
if (ch1 != ch2) {
- if (!ignoreCase || ignoreCase && Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
+ if (!ignoreCase || Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
break;
}
}
@@ -582,4 +587,44 @@
builder.finish();
}
+ public boolean findAndReplace(UTF8StringPointable searchPtr, UTF8StringPointable replacePtr, int replaceLimit,
+ UTF8StringBuilder builder, GrowableArray out) throws IOException {
+ return findAndReplace(this, searchPtr, replacePtr, replaceLimit, builder, out);
+ }
+
+ public static boolean findAndReplace(UTF8StringPointable srcPtr, UTF8StringPointable searchPtr,
+ UTF8StringPointable replacePtr, int replaceLimit, UTF8StringBuilder builder, GrowableArray out)
+ throws IOException {
+ if (replaceLimit < 1) {
+ return false;
+ }
+ int curIdx = find(srcPtr, searchPtr, false);
+ if (curIdx < 0) {
+ return false;
+ }
+ int searchUtfLen = searchPtr.getUTF8Length();
+ int replaceUtfLen = replacePtr.getUTF8Length();
+ int estimatedLen = searchUtfLen > 0 && replaceUtfLen > searchUtfLen
+ ? (int) (((long) srcPtr.getUTF8Length()) * replaceUtfLen / searchUtfLen) : srcPtr.getUTF8Length();
+ builder.reset(out, estimatedLen);
+ builder.appendUtf8StringPointable(srcPtr, srcPtr.getCharStartOffset(), curIdx);
+ builder.appendUtf8StringPointable(replacePtr);
+
+ curIdx += searchUtfLen;
+ int limit = replaceLimit - 1;
+
+ int nextIdx;
+ while (limit > 0 && (nextIdx = find(srcPtr, searchPtr, false, curIdx)) > 0) {
+ builder.appendUtf8StringPointable(srcPtr, srcPtr.getCharStartOffset() + curIdx, nextIdx - curIdx);
+ builder.appendUtf8StringPointable(replacePtr);
+ curIdx = nextIdx + searchUtfLen;
+ limit--;
+ }
+ builder.appendUtf8StringPointable(srcPtr, srcPtr.getCharStartOffset() + curIdx,
+ srcPtr.getUTF8Length() - curIdx);
+
+ builder.finish();
+
+ return true;
+ }
}