Package com.alibaba.wasp.plan.parser

Examples of com.alibaba.wasp.plan.parser.Condition


    }

    byte[] primayKey = RowBuilder.build().genRowkey(primaryKeyPairs);
    DeleteAction action = new DeleteAction(wtableName, primayKey);
    if (context.isGenWholePlan()) {
      Condition entityGroupKeyCondition = ParserUtils.getCondition(table
          .getEntityGroupKey().getName(), eqConditions);
      // Get entityGroupLocation according to entity group key
      EntityGroupLocation entityGroupLocation = this.connection
          .locateEntityGroup(Bytes.toBytes(table.getTableName()), DruidParser
              .convert(table.getColumn(entityGroupKeyCondition.getFieldName()),
                  entityGroupKeyCondition.getValue()));
      action.setEntityGroupLocation(entityGroupLocation);
    }
    List<DeleteAction> actions = new ArrayList<DeleteAction>();
    actions.add(action);
    DeletePlan deletePlan = new DeletePlan(actions);
View Full Code Here


          columnName);
      action.addEntityColumn(fTableName, familyName, columnName,
          field.getType(), value);
    }
    if (context.isGenWholePlan()) {
      Condition entityGroupKeyCondition = ParserUtils.getCondition(table
          .getEntityGroupKey().getName(), conditions);
      // Get entityGroupLocation according to entity group key
      EntityGroupLocation entityGroupLocation = this.connection
          .locateEntityGroup(Bytes.toBytes(table.getTableName()), DruidParser
              .convert(table.getColumn(entityGroupKeyCondition.getFieldName()),
                  entityGroupKeyCondition.getValue()));
      action.setEntityGroupLocation(entityGroupLocation);
    }
    action.setSessionId(context.getSessionId());
    List<UpdateAction> actions = new ArrayList<UpdateAction>();
    actions.add(action);
View Full Code Here

    }

    Action action = null;
    DQLPlan qp = null;

    Condition entityGroupKeyCondition = queryInfo.getField(table
        .getEntityGroupKey().getName());
    if (queryInfo.getType() == QueryInfo.QueryType.GET) {
      byte[] primaryKey = RowBuilder.build().genRowkey(primaryKeyPairs);
      // check if the column is table's primary key.
      action = new GetAction(context.getReadModel(), table.getTableName(),
          primaryKey, this.buildEntityColumnsForGet(table, metaEventOperation,
              selectItem));
      ((GetAction)action).setForUpdate(queryInfo.isForUpdate());
      if (context.isGenWholePlan()) {
        // get entityGroupLocation according to entity group key.
        EntityGroupLocation entityGroupLocation = this.connection
            .locateEntityGroup(Bytes.toBytes(table.getTableName()), DruidParser
                .convert(
                    table.getColumn(entityGroupKeyCondition.getFieldName()),
                    entityGroupKeyCondition.getValue()));
        action.setEntityGroupLocation(entityGroupLocation);
      }
      qp = new LocalQueryPlan((GetAction) action);
      LOG.debug(QueryInfo.QueryType.GET + "  "
          + Bytes.toStringBinary(primaryKey) + " from " + table.getTableName());
    } else if (queryInfo.getType() == QueryInfo.QueryType.SCAN) {
      Index index = metaEventOperation.checkAndGetIndex(table,
          queryInfo.getAllConditionFieldName());

      if (index == null) {
        throw new UnsupportedException("Don't get a Index!");
      }

      boolean isJustUseIndex = index.getIndexKeys().size() >= queryInfo.getAllConditionFieldName().size();
      Pair<byte[], byte[]> startKeyAndEndKey = metaEventOperation.getStartkeyAndEndkey(index, queryInfo);

      Pair<List<ColumnStruct>, List<ColumnStruct>> columnActionPair = this
          .buildEntityColumnsForScan(table, index, metaEventOperation,
              selectItem);
      List<ColumnStruct> selectEntityColumns = columnActionPair.getFirst();
      List<ColumnStruct> selectStoringColumns = columnActionPair.getSecond();
      List<ColumnStruct> conditionNotInIndex = isJustUseIndex ? Collections.<ColumnStruct>emptyList()
          : buildColumnsNotInIndex(table, index, queryInfo);

      // instance scan action.
      action = new ScanAction(context.getReadModel(),
          StorageTableNameBuilder.buildIndexTableName(index),
          table.getTableName(), startKeyAndEndKey.getFirst(),
          startKeyAndEndKey.getSecond(), selectEntityColumns);
      ((ScanAction) action).setStoringColumns(selectStoringColumns);
      ((ScanAction) action).setLimit(limit);
      ((ScanAction) action).setNotIndexConditionColumns(conditionNotInIndex);

      if (entityGroupKeyCondition != null
          && entityGroupKeyCondition.getType() == ConditionType.EQUAL) {
        if (context.isGenWholePlan()) {
          EntityGroupLocation entityGroupLocation = this.connection
              .locateEntityGroup(Bytes.toBytes(table.getTableName()),
                  DruidParser.convert(
                      table.getColumn(entityGroupKeyCondition.getFieldName()),
                      entityGroupKeyCondition.getValue()));
          action.setEntityGroupLocation(entityGroupLocation);
        }
        qp = new LocalQueryPlan((ScanAction) action);
        LOG.debug(QueryInfo.QueryType.SCAN + " startKey "
            + Bytes.toStringBinary(startKeyAndEndKey.getFirst()) + " endKey "
View Full Code Here

    }
    return columns;
  }

  private ColumnStruct buildColumnStruct(FTable table, QueryInfo queryInfo, Field field) throws UnsupportedException {
    Condition condition = queryInfo.getField(field.getName());
    ColumnStruct column = null;
    if(condition.getType() == ConditionType.EQUAL) {
      column = new ColumnStruct(table.getTableName(), field.getFamily(), field.getName(), field.getType(),
          DruidParser.convert(field, condition.getValue()),
          ParserUtils.parseSQLBinaryOperatorToIntValue(SQLBinaryOperator.Equality));
    } else {
      SQLBinaryOperator leftOperator = condition.getLeftOperator();
      SQLBinaryOperator rightOperator = condition.getRightOperator();
      column = new ColumnStruct(table.getTableName(), field.getFamily(), field.getName(), field.getType(),
          DruidParser.convert(field, leftOperator != null ? condition.getLeft() : condition.getRight()),
          ParserUtils.parseSQLBinaryOperatorToIntValue(leftOperator != null ? leftOperator : rightOperator));
    }
    return column;
  }
View Full Code Here

  public List<Pair<String, byte[]>> getPrimaryKeyPairList(FTable table,
      LinkedHashMap<String, Condition> conditions,  LinkedHashMap<String, Condition> rangeConditions)
      throws IOException {
    List<Pair<String, byte[]>> primaryKeys = new ArrayList<Pair<String, byte[]>>();
    for (Field primaryKey : table.getPrimaryKeys().values()) {
      Condition condition = ParserUtils.getCondition(primaryKey.getName(),
          conditions);
      if (condition != null) {
        primaryKeys.add(new Pair<String, byte[]>(condition.getFieldName(),
            DruidParser.convert(table.getColumn(condition.getFieldName()),
                condition.getValue())));
      } else {
        primaryKeys = null;
        break;
      }
    }
View Full Code Here

    if (where instanceof SQLBinaryOpExpr) {
      SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) where;
      SQLBinaryOperator operator = binaryOpExpr.getOperator();
      if (operator == Equality) {// one pair
        SQLIdentifierExpr left = (SQLIdentifierExpr) binaryOpExpr.getLeft();
        Condition value = new Condition(left.getName(),
            Condition.ConditionType.EQUAL, binaryOpExpr.getRight());
        conditions.put(value.getFieldName(), value);
      } else if (operator == SQLBinaryOperator.BooleanAnd) {// multi pair
        SQLExpr left = binaryOpExpr.getLeft();
        SQLExpr right = binaryOpExpr.getRight();
        parse(left, conditions, ranges);
        parse(right, conditions, ranges);
      } else if (operator == SQLBinaryOperator.GreaterThan
          || operator == SQLBinaryOperator.GreaterThanOrEqual
          || operator == SQLBinaryOperator.LessThan
          || operator == SQLBinaryOperator.LessThanOrEqual) {
        SQLIdentifierExpr left = (SQLIdentifierExpr) binaryOpExpr.getLeft();
        String fieldName = left.getName();
        Condition value = getCondition(fieldName, ranges);
        if (value == null) {
          value = new Condition(left.getName(), Condition.ConditionType.RANGE,
              binaryOpExpr.getRight(), operator);
          ranges.put(value.getFieldName(), value);
        } else {
          value.resetValue(binaryOpExpr.getRight(), operator);
        }
      } else {
        throw new UnsupportedException("where clause '" + where + " has '"
            + operator + "' , current this is Unsupported");
      }
View Full Code Here

    List<IndexField> indexFields = new ArrayList<IndexField>();
    LinkedHashMap<String, Condition> eqConditions = queryInfo
            .getEqConditions();
    LinkedHashMap<String, Condition> rangeConditions = queryInfo
            .getRangeConditions();
    Condition range = null;

    for (Field field : index.getIndexKeys().values()) {
      Condition entry = ParserUtils.getCondition(field.getName(),
          eqConditions);
      if(entry != null) {
        addToIndexFields(DruidParser.convert(field, entry.getValue()),
            indexFields, field);
      } else {
        entry = ParserUtils.getCondition(field.getName(),
            rangeConditions);
        if(entry != null) {
View Full Code Here

    LinkedHashMap<String, Condition> fieldValue = new LinkedHashMap<String, Condition>();

    // field name - data type - value

    // index1 - String - =test
    Condition index1Condition = new Condition("index1",
        Condition.ConditionType.EQUAL, new SQLCharExpr("test"));

    // index2 - int - =11
    Condition index2Condition = new Condition("index2",
        Condition.ConditionType.EQUAL, new SQLIntegerExpr(11));

    // index3 - long - <=199
    Condition index3Condition = new Condition("index3",
        Condition.ConditionType.RANGE, new SQLNumberExpr(199),
        SQLBinaryOperator.LessThanOrEqual);

    fieldValue.put(index1Condition.getFieldName(), index1Condition);
    fieldValue.put(index2Condition.getFieldName(), index2Condition);

    LinkedHashMap<String, Condition> ranges = new LinkedHashMap<String, Condition>();
    ranges.put(index3Condition.getFieldName(), index3Condition);
    return new QueryInfo(QueryInfo.QueryType.SCAN, fieldValue, ranges);
  }
View Full Code Here

TOP

Related Classes of com.alibaba.wasp.plan.parser.Condition

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.