1
0
Fork 0

added more for geo

This commit is contained in:
Frank Celler 2012-01-29 21:33:26 +01:00
parent 833176827b
commit 3a11b0c3cd
6 changed files with 275 additions and 12 deletions

4
.gitignore vendored
View File

@ -43,3 +43,7 @@ Doxygen/wiki/
build.sh
commit.sh
.setup-directories
QL/parser.c
QL/parser.h
QL/parser.output
QL/tokens.c

View File

@ -537,6 +537,100 @@ TRI_qry_where_t* TRI_CreateQueryWherePrimaryConstant (TRI_voc_did_t did) {
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- WHERE GEO INDEX
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- private methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup VocBase
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief clones a query condition using the geo index and constants
////////////////////////////////////////////////////////////////////////////////
static TRI_qry_where_t* CloneQueryWhereGeoConstant (TRI_qry_where_t* w) {
TRI_qry_where_geo_const_t* whereClause;
whereClause = (TRI_qry_where_geo_const_t*) w;
return TRI_CreateQueryWhereGeoConstant(whereClause->_iid,
whereClause->_coordinates[0],
whereClause->_coordinates[1]);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief frees a query condition using the geo index and constants
////////////////////////////////////////////////////////////////////////////////
static void FreeQueryWhereGeoConstant (TRI_qry_where_t* w) {
TRI_qry_where_geo_const_t* whereClause;
whereClause = (TRI_qry_where_geo_const_t*) w;
TRI_Free(whereClause);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the lattitude and longitude for constants
////////////////////////////////////////////////////////////////////////////////
static double* CoordinatesQueryWhereGeoConstant (TRI_qry_where_geo_t* w,
TRI_rc_context_t* context) {
TRI_qry_where_geo_const_t* whereClause;
whereClause = (TRI_qry_where_geo_const_t*) w;
return whereClause->_coordinates;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup VocBase
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a query condition using the geo index and a constant
////////////////////////////////////////////////////////////////////////////////
TRI_qry_where_t* TRI_CreateQueryWhereGeoConstant (TRI_idx_iid_t iid,
double latitiude,
double longitude) {
TRI_qry_where_geo_const_t* result;
result = TRI_Allocate(sizeof(TRI_qry_where_geo_const_t));
result->base.base._type = TRI_QRY_WHERE_GEO_CONSTANT;
result->base.base.clone = CloneQueryWhereGeoConstant;
result->base.base.free = FreeQueryWhereGeoConstant;
result->base.base.checkCondition = NULL;
result->base.coordinates = CoordinatesQueryWhereGeoConstant;
result->_coordinates[0] = latitiude;
result->_coordinates[1] = longitude;
return &result->base.base;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- WHERE GENERAL
// -----------------------------------------------------------------------------

View File

@ -324,6 +324,7 @@ TRI_qry_select_general_t;
typedef enum {
TRI_QRY_WHERE_BOOLEAN,
TRI_QRY_WHERE_GENERAL,
TRI_QRY_WHERE_GEO_CONSTANT,
TRI_QRY_WHERE_PRIMARY_CONSTANT
}
TRI_qry_where_type_e;
@ -386,6 +387,29 @@ typedef struct TRI_qry_where_primary_const_s {
}
TRI_qry_where_primary_const_t;
////////////////////////////////////////////////////////////////////////////////
/// @brief geo index where clause
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_qry_where_geo_s {
TRI_qry_where_t base;
double* (*coordinates) (struct TRI_qry_where_geo_s*, TRI_rc_context_t*);
}
TRI_qry_where_geo_t;
////////////////////////////////////////////////////////////////////////////////
/// @brief geo index where clause with a constant document identifier
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_qry_where_geo_const_s {
TRI_qry_where_geo_t base;
TRI_idx_iid_t _iid;
double _coordinates[2];
}
TRI_qry_where_geo_const_t;
////////////////////////////////////////////////////////////////////////////////
/// @brief general query
///
@ -547,6 +571,14 @@ TRI_qry_where_t* TRI_CreateQueryWhereGeneral (char const*);
TRI_qry_where_t* TRI_CreateQueryWherePrimaryConstant (TRI_voc_did_t did);
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a query condition using an geo index and a constants
////////////////////////////////////////////////////////////////////////////////
TRI_qry_where_t* TRI_CreateQueryWhereGeoConstant (TRI_idx_iid_t iid,
double latitiude,
double longitude);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////

View File

@ -1 +1 @@
#define TRIAGENS_VERSION "0.0.8 [1276M]"
#define TRIAGENS_VERSION "0.0.8 [1278M]"

View File

@ -277,6 +277,28 @@ AvocadoFluentQuery2.prototype.toArray = function () {
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns all elements
///
/// @FUN{all()}
///
/// Selects all documents of a collection.
///
/// @verbinclude fluent23
///
/// The corresponding AQL query would be:
///
/// @verbinclude fluent23-aql
////////////////////////////////////////////////////////////////////////////////
AvocadoFluentQuery2.prototype.all = function () {
if (this._execution != null) {
throw "query is already executing";
}
return this.copyQuery();
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
@ -724,16 +746,6 @@ AvocadoFluentQueryInternal.prototype.useNext = function () {
////////////////////////////////////////////////////////////////////////////////
/// @brief returns all elements
///
/// @FUN{all()}
///
/// Selects all documents of a collection.
///
/// @verbinclude fluent23
///
/// The corresponding AQL query would be:
///
/// @verbinclude fluent23-aql
////////////////////////////////////////////////////////////////////////////////
AvocadoCollection.prototype.T_all = function () {

View File

@ -1,3 +1,30 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief tests for "aql.js"
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
///
/// 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.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite
////////////////////////////////////////////////////////////////////////////////
@ -35,7 +62,19 @@ function aqlTestSuite () {
////////////////////////////////////////////////////////////////////////////////
function testCollectionToArray () {
var query;
assertEqual(5, this.collection.T_toArray().length);
try {
query = this.collection.T_all();
query.hasNext();
query.toArray();
fail("trying to execute an executing query");
}
catch (err) {
}
}
////////////////////////////////////////////////////////////////////////////////
@ -46,6 +85,7 @@ function aqlTestSuite () {
assertEqual(5, this.collection.T_skip(0).toArray().length);
assertEqual(4, this.collection.T_skip(1).toArray().length);
assertEqual(3, this.collection.T_skip(2).toArray().length);
assertEqual(5, this.collection.T_skip(null).toArray().length);
try {
this.collection.T_skip(-1);
@ -88,7 +128,7 @@ function aqlTestSuite () {
/// @brief <internal-query>.useRef()
////////////////////////////////////////////////////////////////////////////////
function testInternalQueryNextRef () {
function testInternalQueryUseRef () {
var count = 0;
var query = this.collection.T_all();
@ -99,6 +139,83 @@ function aqlTestSuite () {
assertEqual(5, count);
assertFalse(query.hasNext());
}
////////////////////////////////////////////////////////////////////////////////
/// @brief <query>.skip(<n>)
////////////////////////////////////////////////////////////////////////////////
function testQuerySkip () {
var query;
assertEqual(5, this.collection.T_all().skip(0).toArray().length);
assertEqual(4, this.collection.T_all().skip(1).toArray().length);
assertEqual(3, this.collection.T_all().skip(2).toArray().length);
assertEqual(5, this.collection.T_all().skip(null).toArray().length);
try {
this.collection.T_all().skip(-1);
fail("expected exception for skip(-1)");
}
catch (err) {
}
try {
query = this.collection.T_all();
query.hasNext();
query.skip(1);
fail("trying to execute an executing query");
}
catch (err) {
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief <query>.limit()
////////////////////////////////////////////////////////////////////////////////
function testQueryLimit () {
var query;
assertEqual(3, this.collection.T_all().skip(1).limit(4).skip(1).toArray().length);
assertEqual(2, this.collection.T_all().skip(1).limit(4).limit(-2).toArray().length);
assertEqual(2, this.collection.T_all().skip(1).limit(-4).limit(2).toArray().length);
assertEqual(2, this.collection.T_all().skip(1).limit(3).limit(2).toArray().length);
assertEqual(2, this.collection.T_all().skip(1).limit(-3).limit(-2).toArray().length);
assertEqual(0, this.collection.T_all().skip(1).limit(0).limit(null).toArray().length);
try {
query = this.collection.T_all().skip(1).limit(0);
query.hasNext();
query.limit(null);
fail("trying to execute an executing query");
}
catch (err) {
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief <query>.document(<id>)
////////////////////////////////////////////////////////////////////////////////
function testQueryDocument () {
var query;
var id = this.documents[1]._id;
assertEqual(id, this.collection.T_all().skip(1).limit(-4).limit(2).document(id).next()._id);
try {
query = this.collection.T_all().skip(1).limit(-4).limit(2);
query.hasNext();
query.document(id);
fail("trying to execute an executing query");
}
catch (err) {
}
}
}
////////////////////////////////////////////////////////////////////////////////
@ -107,3 +224,7 @@ function aqlTestSuite () {
jsUnity.run(aqlTestSuite);
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
// End: