/*
 * 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.
 */
/*
 * Description    : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest lists.
 *                  Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
 *                  We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
 * Success        : Yes
 */

drop  dataverse test if exists;
create  dataverse test;

use test;


create type test.AddressType as
 closed {
  number : int32,
  street : string,
  city : string
}

create type test.CustomerType as
 closed {
  cid : int32,
  name : string,
  age : int32?,
  address : AddressType?,
  interests : [string],
  children : [{
          name : string,
          age : int32?
      }
]
}

create  dataset Customers(CustomerType) primary key cid;

create  dataset Customers2(CustomerType) primary key cid;

create  index interests_index  on Customers (interests) type keyword;

write output to asterix_nc1:"rttest/inverted-index-join-noeqjoin_olist-jaccard.adm"
select element {'ainterests':a.interests,'binterests':b.interests}
from  Customers as a,
      Customers2 as b
where (( /*+ indexnl */ test.`similarity-jaccard`(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
;
