<commit_before># 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.
#
# Syntax:
# * lines that start with spaces belong to the previous line
# * lines starting with "#" are remarks.
# * lines starting with "select" are queries, followed by expected results and an empty line
# * lines starting with "explain" are followed by expected query plan and an empty line
# * lines starting with "sql1" are run using the sql1 language
# * lines starting with "xpath2sql" are just converted from xpath to sql2
# * all other lines are are committed into the microkernel (line by line)
# * new tests are typically be added on top, after the syntax docs
# * use ascii character only

# "or" problem (OAK-1432)
xpath2sql /jcr:root/content//element(*, nt:unstructured)
  [((@p1 = 'x1' or @p2 = 'x2') or @p3 = 'x3')]
select [jcr:path], [jcr:score], *
  from [nt:unstructured] as a
  where isdescendantnode(a, '/content')
  and [p1] = 'x1'
  union select [jcr:path], [jcr:score], *
  from [nt:unstructured] as a
  where isdescendantnode(a, '/content')
  and [p2] = 'x2'
  union select [jcr:path], [jcr:score], *
  from [nt:unstructured] as a
  where isdescendantnode(a, '/content')
  and [p3] = 'x3'
  /* xpath ... */

xpath2sql //*[((@jcr:primaryType = 'nt:unstructured' and
  (@p1 = 'x' or @p2 = 'x'))
  or (@p3 = 'x' and @jcr:primaryType = 'nt:folder')) ]
select [jcr:path], [jcr:score], *
  from [nt:base] as a
  where [jcr:primaryType] = 'nt:unstructured'
  and [p1] = 'x'
  union select [jcr:path], [jcr:score], *
  from [nt:base] as a
  where [jcr:primaryType] = 'nt:unstructured'
  and [p2] = 'x'
  union select [jcr:path], [jcr:score], *
  from [nt:base] as a
  where [p3] = 'x'
  and [jcr:primaryType] = 'nt:folder'
  /* xpath ... */

# property names with missing @

xpath2sql /jcr:root/testroot//b/c/d/*
  [@jcr:uuid='1' or @jcr:uuid='2']
select d.[jcr:path] as [jcr:path], d.[jcr:score] as [jcr:score], d.*
  from [nt:base] as a
  inner join [nt:base] as b
  on ischildnode(b, a)
  inner join [nt:base] as c
  on ischildnode(c, b)
  inner join [nt:base] as d
  on ischildnode(d, c)
  where name(a) = 'b'
  and isdescendantnode(a, '/testroot')
  and name(b) = 'c'
  and name(c) = 'd'
  and (d.[jcr:uuid] = '1'
  or d.[jcr:uuid] = '2')
  /* xpath ... */

xpath2sql /jcr:root/test/*[@a='1' and b='2'
  and jcr:contains(c, '3')
  and jcr:contains(., '4')
  and jcr:contains(@d, '5')]
  order by e
select [jcr:path], [jcr:score], *
  from [nt:base] as a<commit_msg>OAK-1372 XPath queries with both path and property restrictions are slow (documentation)<commit_after># 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.
#
# Syntax:
# * lines that start with spaces belong to the previous line
# * lines starting with "#" are remarks.
# * lines starting with "select" are queries, followed by expected results and an empty line
# * lines starting with "explain" are followed by expected query plan and an empty line
# * lines starting with "sql1" are run using the sql1 language
# * lines starting with "xpath2sql" are just converted from xpath to sql2
# * all other lines are are committed into the microkernel (line by line)
# * new tests are typically be added on top, after the syntax docs
# * use ascii character only

# "or" problem (OAK-1432)
xpath2sql /jcr:root/content//element(*, nt:unstructured)
  [((@p1 = 'x1' or @p2 = 'x2') or @p3 = 'x3')]
select [jcr:path], [jcr:score], *
  from [nt:unstructured] as a
  where isdescendantnode(a, '/content')
  and [p1] = 'x1'
  union select [jcr:path], [jcr:score], *
  from [nt:unstructured] as a
  where isdescendantnode(a, '/content')
  and [p2] = 'x2'
  union select [jcr:path], [jcr:score], *
  from [nt:unstructured] as a
  where isdescendantnode(a, '/content')
  and [p3] = 'x3'
  /* xpath ... */

xpath2sql //*[((@jcr:primaryType = 'nt:unstructured' and
  (@p1 = 'x' or @p2 = 'x'))
  or (@p3 = 'x' and @jcr:primaryType = 'nt:folder')) ]
select [jcr:path], [jcr:score], *
  from [nt:base] as a
  where [jcr:primaryType] = 'nt:unstructured'
  and [p1] = 'x'
  union select [jcr:path], [jcr:score], *
  from [nt:base] as a
  where [jcr:primaryType] = 'nt:unstructured'
  and [p2] = 'x'
  union select [jcr:path], [jcr:score], *
  from [nt:base] as a
  where [p3] = 'x'
  and [jcr:primaryType] = 'nt:folder'
  /* xpath ... */

# use the optimal join order (OAK-1372)

xpath2sql /jcr:root/testroot//b/c/d/*
  [@jcr:uuid='1' or @jcr:uuid='2']
select d.[jcr:path] as [jcr:path], d.[jcr:score] as [jcr:score], d.*
  from [nt:base] as a
  inner join [nt:base] as b
  on ischildnode(b, a)
  inner join [nt:base] as c
  on ischildnode(c, b)
  inner join [nt:base] as d
  on ischildnode(d, c)
  where name(a) = 'b'
  and isdescendantnode(a, '/testroot')
  and name(b) = 'c'
  and name(c) = 'd'
  and (d.[jcr:uuid] = '1'
  or d.[jcr:uuid] = '2')
  /* xpath ... */

# property names with missing @

xpath2sql /jcr:root/test/*[@a='1' and b='2'
  and jcr:contains(c, '3')
  and jcr:contains(., '4')
  and jcr:contains(@d, '5')]
  order by e
select [jcr:path], [jcr:score], *
  from [nt:base] as a
{'fraction_non_alphanumeric': 0.14296730413325107, 'fraction_numerical': 0.014497223935842072, 'mean_word_length': 3.9579510703363914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1089533', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2294, 'n_words': 828}