public function setUp() { $this->queryObject = new Query(); $this->queryObject->setQuery(new AndNode([new AndNode([new EqNode('q', null), new NeNode('q', null), new LeNode('q', 'r'), new GeNode('q', 'u')]), new OrNode([new LtNode('q', 't'), new GtNode('q', 'y'), new InNode('q', ['a', 's', 'd', 'f', 'g'])])])); $this->queryObject->setSelect(new XSelectNode(['q', new AggregateFunctionNode('max', 'q'), new AggregateFunctionNode('min', 'q'), new AggregateFunctionNode('count', 'q')])); $this->queryObject->setSort(new SortNode(['q' => -1, 'w' => 1, 'e' => 1])); $this->queryObject->setLimit(new LimitNode(20, 30)); $this->rqlString = "and(and(eq(q,null()),ne(q,null()),le(q,r),ge(q,u)),or(lt(q,t),gt(q,y),in(q,(a,s,d,f,g))))"; $this->rqlString .= "&limit(20,30)"; $this->rqlString .= "&sort(-q,+w,e)"; $this->rqlString .= "&select(q,max(q),min(q),count(q))"; }
public function provider_query() { $emptyQuery = new Query(); $queryWithAndNode = new Query(); $queryWithAndNode->setQuery(new AndNode([new LtNode('price', 23), new NeNode('icon', 'icon1.jpg')])); $queryWithSelect = new Query(); $queryWithSelect->setSelect(new SelectNode(['price', 'icon'])); $queryWithSort = new Query(); $queryWithSort->setSort(new SortNode(['price' => -1, 'icon' => +1])); $queryWithSelectProps = new Query(); $queryWithSelectProps->setSelect(new SelectNode([StoreCatalog::PROP_LINKED_URL_TABLE_NAME])); return array(array($emptyQuery, array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon3.jpg']), array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon3.jpg'])), array($queryWithAndNode, array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon3.jpg']), array(['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'])), array($queryWithSelect, array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon3.jpg']), array(['price' => '21', 'icon' => 'icon1.jpg'], ['price' => '22', 'icon' => 'icon2.jpg'], ['price' => '23', 'icon' => 'icon3.jpg'])), array($queryWithSort, array(['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon6.jpg'], ['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '22', 'icon' => 'icon3.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon5.jpg']), array(['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon5.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon6.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '22', 'icon' => 'icon3.jpg'], ['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'])), array($queryWithSelectProps, array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg', StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com', 'alt' => 'Pot1'], ['url' => 'http://google.com1', 'alt' => 'Pot2']]], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg', StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com2', 'alt' => 'Pot3'], ['url' => 'http://google.com3', 'alt' => 'Pot4']]]), array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg', StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com', 'alt' => 'Pot1'], ['url' => 'http://google.com1', 'alt' => 'Pot2']]], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg', StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com2', 'alt' => 'Pot3'], ['url' => 'http://google.com3', 'alt' => 'Pot4']]]))); }
/** * Checks a status of processes. * * If the process finished, reads its log files and return the status of finishing and errors/output */ public function checkProcess() { // TODO: проверить все процессы. Зависшие закрыть принудительно (reject), остальные обработать $sortNode = new SortNode(['startedAt' => +1]); $query = new Query(); $query->setSort($sortNode); $rows = $this->pidDataStore->query($query); foreach ($rows as $row) { $pId = intval($row['pId']); // checks timeout $expireTime = floatval($row['startedAt']) + intval($row['timeout']); if ($expireTime <= UTCTime::getUTCTimestamp()) { $this->killProcess($pId); } // checks process existing if (!posix_kill($pId, 0)) { // The process is finished $this->postFinishProcess($row); $this->pidDataStore->delete($row['id']); } } }
public function testQuery_limitOffsetCombo() { $this->_initObject(); $query = new Query(); $eqNode1 = new ScalarOperator\EqNode('fString', 'val2'); $query->setQuery($eqNode1); $sortNode = new Node\SortNode(['id' => '1']); $query->setSort($sortNode); $selectNode = new Node\SelectNode(['fFloat']); $query->setSelect($selectNode); $limitNode = new Node\LimitNode(2, 1); $query->setLimit($limitNode); $queryArray = $this->object->query($query); $this->assertEquals(array('fFloat' => $this->_itemsArrayDelault[3 - 1]['fFloat']), $queryArray[1 - 1]); $this->assertEquals(array('fFloat' => $this->_itemsArrayDelault[4 - 1]['fFloat']), $queryArray[2 - 1]); $this->assertEquals(2, count($queryArray)); }
/** * * @see Iterator * @return array */ public function next() { $identifier = $this->dataStore->getIdentifier(); $query = new Query(); $selectNode = new Node\SelectNode([$identifier]); $query->setSelect($selectNode); $sortNode = new Node\SortNode([$identifier => 1]); $query->setSort($sortNode); $limitNode = new Node\LimitNode(1, 0); $query->setLimit($limitNode); $gtNode = new ScalarOperator\GtNode($identifier, $this->index); $query->setQuery($gtNode); $queryArray = $this->dataStore->query($query); $this->index = $queryArray === [] ? null : $queryArray[0][$identifier]; }
/** * @param SortNode $sort * @return $this */ public function addSort(SortNode $sort) { $this->query->setSort($sort); return $this; }
public function test__query_with_sort() { $this->__init(); for ($i = 1; $i < 10; $i++) { $data = ['title' => 'title_' . $i, 'price' => 100 * $i]; $this->object->create($data); $this->assertEquals($i, $this->object->count()); } $query = new Query(); $query->setSort(new SortNode([SysEntities::TABLE_NAME . '.add_date' => -1])); $result = $this->object->query($query); $res = true; $prev = $result[0]; if (count($result) == 1) { $res = true; } for ($i = 0; $i < count($result); $i++) { $curr = $result[$i]; if ($prev['add_date'] < $curr['add_date']) { $res = false; break; } $prev = $curr; } $this->assertEquals(true, $res); }