/**
 * Copyright (C) 2014-2016 LinkedIn Corp. (pinot-core@linkedin.com)
 *
 * Licensed 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 com.linkedin.pinot.core.predicate;

import com.linkedin.pinot.common.request.BrokerRequest;
import com.linkedin.pinot.common.utils.StringUtil;
import com.linkedin.pinot.common.utils.request.FilterQueryTree;
import com.linkedin.pinot.common.utils.request.RequestUtils;
import com.linkedin.pinot.core.common.Predicate;
import com.linkedin.pinot.core.common.predicate.InPredicate;
import com.linkedin.pinot.pql.parsers.Pql2Compiler;
import java.util.Arrays;
import org.testng.Assert;
import org.testng.annotations.Test;


/**
 * Unit test for {@link InPredicate}
 */
public class InPredicateTest {

  /**
   * This test ensures the FilterQueryTree & InPredicate are constructed correctly for both cases of:
   * <ul>
   *   <li> Splitting the in clause values. </li>
   *   <li> Joining the in clause values with delimiter. </li>
   * </ul>
   */
  @Test
  public void testSplitInClause() {
    Pql2Compiler compiler = new Pql2Compiler();
    String query = "select * from foo where values in ('abc', 'xyz', '123')";

    String[] expectedValues = new String[]{"abc", "xyz", "123"};
    Arrays.sort(expectedValues); /* InPredicateAstNode sorts the predicate values. */

    /* Test split case */
    BrokerRequest brokerRequest = compiler.compileToBrokerRequest(query, true /*splitInClause*/);
    FilterQueryTree filterQueryTree = RequestUtils.generateFilterQueryTree(brokerRequest);
    InPredicate predicate = (InPredicate) Predicate.newPredicate(filterQueryTree);
    String[] actualValues = predicate.getInRange();

    Assert.assertEquals(actualValues, expectedValues);
    Assert.assertEquals(filterQueryTree.getValue(), Arrays.asList(expectedValues));

    /* Test join case */
    brokerRequest = compiler.compileToBrokerRequest(query, false /*splitInClause*/);
    filterQueryTree = RequestUtils.generateFilterQueryTree(brokerRequest);
    predicate = (InPredicate) Predicate.newPredicate(filterQueryTree);
    actualValues = predicate.getInRange();

    Assert.assertEquals(actualValues, expectedValues);
    Assert.assertEquals(filterQueryTree.getValue().get(0), StringUtil.join(InPredicate.DELIMITER, expectedValues));
  }
}


@@ -731,16 +731,70 @@
 equest;%0A
+import com.linkedin.pinot.common.utils.EqualityUtils;%0A
 import c
@@ -2201,32 +2201,63 @@
 te.getInRange();
+%0A    Arrays.sort(actualValues);
 %0A%0A    Assert.ass
@@ -2306,38 +2306,69 @@
    Assert.assert
-Equals
+True(EqualityUtils.isEqualIgnoreOrder
 (filterQueryTree
@@ -2410,16 +2410,17 @@
 Values))
+)
 ;%0A%0A    /
@@ -2712,16 +2712,47 @@
 Range();
+%0A    Arrays.sort(actualValues);
 %0A%0A    As
@@ -2804,36 +2804,31 @@
 s);%0A    
-Assert.assertEquals(
+actualValues = 
 filterQu
@@ -2856,25 +2856,14 @@
 t(0)
-, StringUtil.join
+.split
 (InP
@@ -2880,16 +2880,86 @@
 ELIMITER
+);%0A    Arrays.sort(actualValues);%0A    Assert.assertEquals(actualValues
 , expect
@@ -2967,17 +2967,16 @@
 dValues)
-)
 ;%0A  %7D%0A%7D%0A

Build fix: PR's 1812 and 1819 were incompatible, causing a test failure. (#1822)