Package org.apache.helix.josql

Examples of org.apache.helix.josql.ClusterJosqlQueryProcessor


    String queryTarget = recipientCriteria.getDataSource().toString() + ClusterJosqlQueryProcessor.FLATTABLE;
   
    String josql = "SELECT DISTINCT " + queryFields
                 + " FROM " + queryTarget + " WHERE "
                 + matchCondition;
    ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(manager);
    List<Object> result = new ArrayList<Object>();
    try
    {
      logger.info("JOSQL query: " + josql);
      result = p.runJoSqlQuery(josql, null, null);
    }
    catch (Exception e)
    {
      logger.error("", e);
      return selected;
View Full Code Here


        "FROM LIVEINSTANCES " +
        "WHERE getMapFieldValue( getZNRecordFromMap(:IDEALSTATES , 'TestDB'), :partitionName, :_currObj.id)='MASTER'";
    Map<String, Object> bindVariables = new HashMap<String, Object>();
    bindVariables.put("partitionName", "TestDB_2");
   
    ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(manager);
    List<Object> result = p.runJoSqlQuery(SQL, bindVariables, null);
   
    Assert.assertEquals(result.size(), 1);
    List<Object> firstList = (List<Object>) result.get(0);
    Assert.assertTrue(((String)(firstList.get(0))).equalsIgnoreCase("localhost_12921"));
   
    // Find the live instances names that hosts Partition TestDB_10 according to idealstate
   
    SQL = "SELECT id  " +
        "FROM LIVEINSTANCES " +
        "WHERE hasMapFieldKey( getZNRecordFromMap(:IDEALSTATES, 'TestDB'), :partitionName, :_currObj.id)='true'";
    p = new ClusterJosqlQueryProcessor(manager);
    bindVariables.put("partitionName", "TestDB_10");
    result = p.runJoSqlQuery(SQL, bindVariables, null);
   
    Assert.assertEquals(result.size(), 3);
    Set<String> hosts = new HashSet<String>();
    for(Object o : result)
    {
      String val = (String) ((List<Object>)o).get(0);
      hosts.add(val);
    }
    Assert.assertTrue(hosts.contains("localhost_12918"));
    Assert.assertTrue(hosts.contains("localhost_12920"));
    Assert.assertTrue(hosts.contains("localhost_12921"));
   
    // Find the partitions on host localhost_12919 and is on MASTER state
    SQL = "SELECT id  " +
        "FROM PARTITIONS " +
        "WHERE getMapFieldValue( getZNRecordFromMap(:EXTERNALVIEW, 'TestDB'), id, :instanceName)='MASTER'";
    p = new ClusterJosqlQueryProcessor(manager);
    bindVariables.clear();
    bindVariables.put("instanceName", "localhost_12919");
    result = p.runJoSqlQuery(SQL, bindVariables, null);
   
    Assert.assertEquals(result.size(), 4);
    Set<String> partitions = new HashSet<String>();
    for(Object o : result)
    {
      String val = (String) ((List<Object>)o).get(0);
      partitions.add(val);
    }
    Assert.assertTrue(partitions.contains("TestDB_6"));
    Assert.assertTrue(partitions.contains("TestDB_7"));
    Assert.assertTrue(partitions.contains("TestDB_9"));
    Assert.assertTrue(partitions.contains("TestDB_14"));

    // Find the partitions on host localhost_12919 and is on MASTER state
    // Same as above but according to currentstates
    SQL = "SELECT id  " +
        "FROM PARTITIONS " +
        "WHERE getMapFieldValue( getZNRecordFromMap(:CURRENTSTATES, :instanceName, 'TestDB'), :_currObj.id, :mapFieldKey)=:partitionState";
   
    p = new ClusterJosqlQueryProcessor(manager);
    bindVariables.clear();
    bindVariables.put("instanceName", "localhost_12919");
    bindVariables.put("mapFieldKey", "CURRENT_STATE");
    bindVariables.put("partitionState", "MASTER");
   
    result = p.runJoSqlQuery(SQL,  bindVariables, null);
   
    Assert.assertEquals(result.size(), 4);
    partitions.clear();
    partitions = new HashSet<String>();
    for(Object o : result)
    {
      String val = (String) ((List<Object>)o).get(0);
      partitions.add(val);
    }
    Assert.assertTrue(partitions.contains("TestDB_6"));
    Assert.assertTrue(partitions.contains("TestDB_7"));
    Assert.assertTrue(partitions.contains("TestDB_9"));
    Assert.assertTrue(partitions.contains("TestDB_14"));
   
    // get node name that hosts a certain partition with certain state
   
    SQL = "SELECT id  " +
        "FROM LIVEINSTANCES " +
        "WHERE getMapFieldValue( getZNRecordFromMap(:CURRENTSTATES, id, 'TestDB'), :partitionName, :mapFieldKey)=:partitionState";
   
    p = new ClusterJosqlQueryProcessor(manager);
    bindVariables.clear();
    bindVariables.put("partitionName", "TestDB_8");
    bindVariables.put("mapFieldKey", "CURRENT_STATE");
    bindVariables.put("partitionState", "SLAVE");
   
    result = p.runJoSqlQuery(SQL,  bindVariables, null);
   
    Assert.assertEquals(result.size(), 2);
    partitions.clear();
    partitions = new HashSet<String>();
    for(Object o : result)
View Full Code Here

  }
 
  @Test (groups = {"unitTest"})
  public void parseFromTarget()
  {
    ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(null);
    String sql = "SELECT id  " +
        "FROM LIVEINSTANCES ";
    String from = p.parseFromTarget(sql);
    Assert.assertTrue(from.equals("LIVEINSTANCES"));
   
    sql = "SELECT id      " +
        "FROM    LIVEINSTANCES  WHERE 1=2";
   
    from = p.parseFromTarget(sql);
    Assert.assertTrue(from.equals("LIVEINSTANCES"));
   
    sql = "SELECT id      " +
        "FROM LIVEINSTANCES";
   
    from = p.parseFromTarget(sql);
    Assert.assertTrue(from.equals("LIVEINSTANCES"));
   
    sql = "SELECT id      " +
        " LIVEINSTANCES where tt=00";
    boolean exceptionThrown = false;
    try
    {
      from = p.parseFromTarget(sql);
    }
    catch(HelixException e)
    {
      exceptionThrown = true;
    }
View Full Code Here

          " AND mapSubKey LIKE '%' " +
          " AND mapValue LIKE 'SLAVE' " +
          " AND mapSubKey IN ((SELECT [*]id FROM :LIVEINSTANCES)) " +
          " ORDER BY parseInt(getMapFieldValue(getZNRecordFromMap(:scnMap, mapSubKey), 'SCN', mapKey))";

    ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(manager);
    List<Object> result = p.runJoSqlQuery(SQL, bindVariables, null);
    int prevSCN = -1;
    for(Object row : result)
    {
      List<String> stringRow = (List<String>)row;
      Assert.assertTrue(stringRow.get(1).equals("SLAVE"));
View Full Code Here

            + "FROM LIVEINSTANCES "
            + "WHERE getMapFieldValue( getZNRecordFromMap(:IDEALSTATES , 'TestDB'), :partitionName, :_currObj.id)='MASTER'";
    Map<String, Object> bindVariables = new HashMap<String, Object>();
    bindVariables.put("partitionName", "TestDB_2");

    ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(manager);
    List<Object> result = p.runJoSqlQuery(SQL, bindVariables, null);

    Assert.assertEquals(result.size(), 1);
    List<Object> firstList = (List<Object>) result.get(0);
    Assert.assertTrue(((String) (firstList.get(0))).equalsIgnoreCase("localhost_12921"));

    // Find the live instances names that hosts Partition TestDB_10 according to idealstate

    SQL =
        "SELECT id  "
            + "FROM LIVEINSTANCES "
            + "WHERE hasMapFieldKey( getZNRecordFromMap(:IDEALSTATES, 'TestDB'), :partitionName, :_currObj.id)='true'";
    p = new ClusterJosqlQueryProcessor(manager);
    bindVariables.put("partitionName", "TestDB_10");
    result = p.runJoSqlQuery(SQL, bindVariables, null);

    Assert.assertEquals(result.size(), 3);
    Set<String> hosts = new HashSet<String>();
    for (Object o : result) {
      String val = (String) ((List<Object>) o).get(0);
      hosts.add(val);
    }
    Assert.assertTrue(hosts.contains("localhost_12918"));
    Assert.assertTrue(hosts.contains("localhost_12920"));
    Assert.assertTrue(hosts.contains("localhost_12921"));

    // Find the partitions on host localhost_12919 and is on MASTER state
    SQL =
        "SELECT id  "
            + "FROM PARTITIONS "
            + "WHERE getMapFieldValue( getZNRecordFromMap(:EXTERNALVIEW, 'TestDB'), id, :instanceName)='MASTER'";
    p = new ClusterJosqlQueryProcessor(manager);
    bindVariables.clear();
    bindVariables.put("instanceName", "localhost_12919");
    result = p.runJoSqlQuery(SQL, bindVariables, null);

    Assert.assertEquals(result.size(), 4);
    Set<String> partitions = new HashSet<String>();
    for (Object o : result) {
      String val = (String) ((List<Object>) o).get(0);
      partitions.add(val);
    }
    Assert.assertTrue(partitions.contains("TestDB_6"));
    Assert.assertTrue(partitions.contains("TestDB_7"));
    Assert.assertTrue(partitions.contains("TestDB_9"));
    Assert.assertTrue(partitions.contains("TestDB_14"));

    // Find the partitions on host localhost_12919 and is on MASTER state
    // Same as above but according to currentstates
    SQL =
        "SELECT id  "
            + "FROM PARTITIONS "
            + "WHERE getMapFieldValue( getZNRecordFromMap(:CURRENTSTATES, :instanceName, 'TestDB'), :_currObj.id, :mapFieldKey)=:partitionState";

    p = new ClusterJosqlQueryProcessor(manager);
    bindVariables.clear();
    bindVariables.put("instanceName", "localhost_12919");
    bindVariables.put("mapFieldKey", "CURRENT_STATE");
    bindVariables.put("partitionState", "MASTER");

    result = p.runJoSqlQuery(SQL, bindVariables, null);

    Assert.assertEquals(result.size(), 4);
    partitions.clear();
    partitions = new HashSet<String>();
    for (Object o : result) {
      String val = (String) ((List<Object>) o).get(0);
      partitions.add(val);
    }
    Assert.assertTrue(partitions.contains("TestDB_6"));
    Assert.assertTrue(partitions.contains("TestDB_7"));
    Assert.assertTrue(partitions.contains("TestDB_9"));
    Assert.assertTrue(partitions.contains("TestDB_14"));

    // get node name that hosts a certain partition with certain state

    SQL =
        "SELECT id  "
            + "FROM LIVEINSTANCES "
            + "WHERE getMapFieldValue( getZNRecordFromMap(:CURRENTSTATES, id, 'TestDB'), :partitionName, :mapFieldKey)=:partitionState";

    p = new ClusterJosqlQueryProcessor(manager);
    bindVariables.clear();
    bindVariables.put("partitionName", "TestDB_8");
    bindVariables.put("mapFieldKey", "CURRENT_STATE");
    bindVariables.put("partitionState", "SLAVE");

    result = p.runJoSqlQuery(SQL, bindVariables, null);

    Assert.assertEquals(result.size(), 2);
    partitions.clear();
    partitions = new HashSet<String>();
    for (Object o : result) {
View Full Code Here

  @Test(groups = {
    "unitTest"
  })
  public void parseFromTarget() {
    ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(null);
    String sql = "SELECT id  " + "FROM LIVEINSTANCES ";
    String from = p.parseFromTarget(sql);
    Assert.assertTrue(from.equals("LIVEINSTANCES"));

    sql = "SELECT id      " + "FROM    LIVEINSTANCES  WHERE 1=2";

    from = p.parseFromTarget(sql);
    Assert.assertTrue(from.equals("LIVEINSTANCES"));

    sql = "SELECT id      " + "FROM LIVEINSTANCES";

    from = p.parseFromTarget(sql);
    Assert.assertTrue(from.equals("LIVEINSTANCES"));

    sql = "SELECT id      " + " LIVEINSTANCES where tt=00";
    boolean exceptionThrown = false;
    try {
      from = p.parseFromTarget(sql);
    } catch (HelixException e) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
  }
View Full Code Here

            + " AND mapSubKey LIKE '%' "
            + " AND mapValue LIKE 'SLAVE' "
            + " AND mapSubKey IN ((SELECT [*]id FROM :LIVEINSTANCES)) "
            + " ORDER BY parseInt(getMapFieldValue(getZNRecordFromMap(:scnMap, mapSubKey), 'SCN', mapKey))";

    ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(manager);
    List<Object> result = p.runJoSqlQuery(SQL, bindVariables, null);
    int prevSCN = -1;
    for (Object row : result) {
      List<String> stringRow = (List<String>) row;
      Assert.assertTrue(stringRow.get(1).equals("SLAVE"));
      int scn = Integer.parseInt(stringRow.get(2));
View Full Code Here

    String queryTarget =
        recipientCriteria.getDataSource().toString() + ClusterJosqlQueryProcessor.FLATTABLE;

    String josql =
        "SELECT DISTINCT " + queryFields + " FROM " + queryTarget + " WHERE " + matchCondition;
    ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(manager);
    List<Object> result = new ArrayList<Object>();
    try {
      logger.info("JOSQL query: " + josql);
      result = p.runJoSqlQuery(josql, null, null);
    } catch (Exception e) {
      logger.error("", e);
      return selected;
    }
View Full Code Here

TOP

Related Classes of org.apache.helix.josql.ClusterJosqlQueryProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.