Package org.apache.accumulo.examples.wikisearch.parser.RangeCalculator

Examples of org.apache.accumulo.examples.wikisearch.parser.RangeCalculator.RangeBounds


      while (children.hasMoreElements()) {
        RewriterTreeNode child = (RewriterTreeNode) children.nextElement();
        if (child.getType() == ParserTreeConstants.JJTLENODE || child.getType() == ParserTreeConstants.JJTLTNODE) {
          Text fName = new Text(child.getFieldName());
          if (rangeMap.containsKey(fName)) {
            RangeBounds rb = rangeMap.get(fName);
            if (rb.getLower() != null) {
              log.error("testBoundedRangeExistence, two lower bounds exist for bounded range.");
            }
            rb.setLower(new Text(child.getFieldValue()));
          } else {
            RangeBounds rb = new RangeBounds();
            rb.setLower(new Text(child.getFieldValue()));
            rangeMap.put(new Text(child.getFieldName()), rb);
          }
         
        } else if (child.getType() == ParserTreeConstants.JJTGENODE || child.getType() == ParserTreeConstants.JJTGTNODE) {
          Text fName = new Text(child.getFieldName());
          if (rangeMap.containsKey(fName)) {
            RangeBounds rb = rangeMap.get(fName);
            if (rb.getUpper() != null) {
              log.error("testBoundedRangeExistence, two Upper bounds exist for bounded range.");
            }
            rb.setUpper(new Text(child.getFieldValue()));
          } else {
            RangeBounds rb = new RangeBounds();
            rb.setUpper(new Text(child.getFieldValue()));
            rangeMap.put(new Text(child.getFieldName()), rb);
          }
        }
      }
     
      for (Entry<Text,RangeBounds> entry : rangeMap.entrySet()) {
        RangeBounds rb = entry.getValue();
        if (rb.getLower() == null || rb.getUpper() == null) {
          // unbounded range, remove
          if (log.isDebugEnabled()) {
            log.debug("testBoundedRangeExistence: Unbounded Range detected, removing entry from rangeMap");
          }
          rangeMap.remove(entry.getKey());
View Full Code Here


            if (child.getType() == JexlOperatorConstants.JJTGTNODE) {
              if (log.isDebugEnabled()) {
                log.debug("refactor: GT " + child.getContents());
              }
              if (ranges.containsKey(child.getFieldName())) {
                RangeBounds rb = ranges.get(child.getFieldName());
                rb.setLower(child.getFieldValue());
              } else {
                RangeBounds rb = new RangeBounds();
                rb.setLower(child.getFieldValue());
                ranges.put(child.getFieldName(), rb);
              }
            } else if (child.getType() == JexlOperatorConstants.JJTGENODE) {
              if (log.isDebugEnabled()) {
                log.debug("refactor: GE " + child.getContents());
              }
              if (ranges.containsKey(child.getFieldName())) {
                RangeBounds rb = ranges.get(child.getFieldName());
                rb.setLower(child.getFieldValue());
              } else {
                RangeBounds rb = new RangeBounds();
                rb.setLower(child.getFieldValue());
                ranges.put(child.getFieldName(), rb);
              }
            } else if (child.getType() == JexlOperatorConstants.JJTLTNODE) {
              if (log.isDebugEnabled()) {
                log.debug("refactor: LT " + child.getContents());
              }
              if (ranges.containsKey(child.getFieldName())) {
                RangeBounds rb = ranges.get(child.getFieldName());
                rb.setUpper(child.getFieldValue());
              } else {
                RangeBounds rb = new RangeBounds();
                rb.setUpper(child.getFieldValue());
                ranges.put(child.getFieldName(), rb);
              }
            } else if (child.getType() == JexlOperatorConstants.JJTLENODE) {
              if (log.isDebugEnabled()) {
                log.debug("refactor: LE " + child.getContents());
              }
              if (ranges.containsKey(child.getFieldName())) {
                RangeBounds rb = ranges.get(child.getFieldName());
                rb.setUpper(child.getFieldValue());
              } else {
                RangeBounds rb = new RangeBounds();
                rb.setUpper(child.getFieldValue());
                ranges.put(child.getFieldName(), rb);
              }
            }
          }
        }
        if (allNegated) {
          node.setChildrenAllNegated(true);
        }
       
        // see if the AND node had a range.
        if (node.getType() == ParserTreeConstants.JJTANDNODE) {
         
          // if(ranges.containsKey(node.getFieldName())){
          if (!ranges.isEmpty()) {
            // we have a range, process it
            if (node.getChildCount() <= 2 && ranges.size() == 1) {
              if (log.isDebugEnabled()) {
                log.debug("AND range 2 children or less");
              }
              // only has a range, modify the node
              node.setType(ParserTreeConstants.JJTORNODE);
              node.removeAllChildren();
              // RangeBounds rb = ranges.get(node.getFieldName());
             
              for (Entry<Text,RangeBounds> entry : ranges.entrySet()) {
                Text fName = entry.getKey();
                RangeBounds rb = entry.getValue();
                node.setFieldName(fName);
                node.setFieldValue(new Text(""));
                node.setLowerBound(rb.getLower());
                node.setUpperBound(rb.getUpper());
                node.setRangeNode(true);
              }
             
              rangerators.add(node);
             
              if (log.isDebugEnabled()) {
                log.debug("refactor: " + node.getContents());
                log.debug("refactor: " + node.getLowerBound() + "  " + node.getUpperBound());
              }
             
            } else {
              if (log.isDebugEnabled()) {
                log.debug("AND range more than 2 children");
              }
              // node has range plus other children, create another node from the range
              // remove lt,le,gt,ge from parent and push in a single node
             
              // removing nodes via enumeration doesn't work, push into a list
              // and walk backwards
              List<BooleanLogicTreeNode> temp = new ArrayList<BooleanLogicTreeNode>();
              Enumeration<?> e = node.children();
              while (e.hasMoreElements()) {
                BooleanLogicTreeNode c = (BooleanLogicTreeNode) e.nextElement();
                temp.add(c);
              }
             
              for (int j = temp.size() - 1; j >= 0; j--) {
                BooleanLogicTreeNode c = temp.get(j);
                if (c.getType() == JexlOperatorConstants.JJTLENODE || c.getType() == JexlOperatorConstants.JJTLTNODE
                    || c.getType() == JexlOperatorConstants.JJTGENODE || c.getType() == JexlOperatorConstants.JJTGTNODE) {
                  c.removeFromParent();
                }
              }
             
              for (Entry<Text,RangeBounds> entry : ranges.entrySet()) {
                Text fName = entry.getKey();
                BooleanLogicTreeNode nchild = new BooleanLogicTreeNode(ParserTreeConstants.JJTORNODE, fName.toString(), "");
                RangeBounds rb = entry.getValue();
                nchild.setFieldValue(new Text(""));
                nchild.setLowerBound(rb.getLower());
                nchild.setUpperBound(rb.getUpper());
                nchild.setRangeNode(true);
                node.add(nchild);
                rangerators.add(nchild);
              }
             
View Full Code Here

TOP

Related Classes of org.apache.accumulo.examples.wikisearch.parser.RangeCalculator.RangeBounds

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.