Example #1
0
func ParseQuery(query string) ([]*Query, error) {
	queryString := C.CString(query)
	defer C.free(unsafe.Pointer(queryString))
	q := C.parse_query(queryString)
	defer C.close_query(&q)

	if q.error != nil {
		str := C.GoString(q.error.err)
		err := fmt.Errorf("Error at %d:%d. %s", q.error.line, q.error.column, str)
		return nil, err
	}

	if q.select_query != nil {
		selectQuery, err := parseSelectQuery(query, q.select_query)
		if err != nil {
			return nil, err
		}
		return []*Query{&Query{SelectQuery: selectQuery}}, nil
	}
	deleteQuery, err := parseDeleteQuery(query, q.delete_query)
	if err != nil {
		return nil, err
	}
	return []*Query{&Query{DeleteQuery: deleteQuery}}, nil
}
Example #2
0
func ParseQuery(query string) ([]*Query, error) {
	queryString := C.CString(query)
	defer C.free(unsafe.Pointer(queryString))
	q := C.parse_query(queryString)
	defer C.close_query(&q)

	if q.error != nil {
		str := C.GoString(q.error.err)
		return nil, &QueryError{
			firstLine:   int(q.error.first_line),
			firstColumn: int(q.error.first_column) - 1,
			lastLine:    int(q.error.last_line),
			lastColumn:  int(q.error.last_column) - 1,
			errorString: str,
			queryString: query,
		}
	}

	if q.list_series_query != nil {
		var value *Value
		var err error
		t := Series
		if q.list_series_query.has_regex != 0 {
			t = SeriesWithRegex
			value, err = GetValue(q.list_series_query.regex)
			if err != nil {
				return nil, err
			}
		}
		return []*Query{{QueryString: query, ListQuery: &ListQuery{Type: t, value: value}}}, nil
	}

	if q.list_continuous_queries_query != 0 {
		return []*Query{{QueryString: query, ListQuery: &ListQuery{Type: ContinuousQueries}}}, nil
	}

	if q.select_query != nil {
		selectQuery, err := parseSelectQuery(q.select_query)
		if err != nil {
			return nil, err
		}

		return []*Query{{QueryString: query, SelectQuery: selectQuery}}, nil
	} else if q.delete_query != nil {
		deleteQuery, err := parseDeleteQuery(q.delete_query)
		if err != nil {
			return nil, err
		}
		return []*Query{{QueryString: query, DeleteQuery: deleteQuery}}, nil
	} else if q.drop_series_query != nil {
		dropSeriesQuery, err := parseDropSeriesQuery(query, q.drop_series_query)
		if err != nil {
			return nil, err
		}
		return []*Query{{QueryString: query, DropSeriesQuery: dropSeriesQuery}}, nil
	} else if q.drop_query != nil {
		return []*Query{{QueryString: query, DropQuery: &DropQuery{Id: int(q.drop_query.id)}}}, nil
	}
	return nil, fmt.Errorf("Unknown query type encountered")
}
Example #3
0
func ParseQuery(query string) ([]*Query, error) {
	//fmt.Println("REACHED HERE")
	queryString := C.CString(query)
	defer C.free(unsafe.Pointer(queryString))
	q := C.parse_query(queryString)
	defer C.close_query(&q)

	if q.error != nil {
		str := C.GoString(q.error.err)
		return nil, &QueryError{
			firstLine:   int(q.error.first_line),
			firstColumn: int(q.error.first_column) - 1,
			lastLine:    int(q.error.last_line),
			lastColumn:  int(q.error.last_column) - 1,
			errorString: str,
			queryString: query,
		}
	}

	if q.list_series_query != 0 {
		return []*Query{{QueryString: query, ListQuery: &ListQuery{Type: Series}}}, nil
	}

	if q.list_continuous_queries_query != 0 {
		return []*Query{{QueryString: query, ListQuery: &ListQuery{Type: ContinuousQueries}}}, nil
	}

	if q.select_query != nil {
		selectQuery, err := parseSelectQuery(q.select_query)
		if err != nil {
			return nil, err
		}

		return []*Query{{QueryString: query, SelectQuery: selectQuery}}, nil
	} else if q.delete_query != nil {
		deleteQuery, err := parseDeleteQuery(q.delete_query)
		if err != nil {
			return nil, err
		}
		return []*Query{{QueryString: query, DeleteQuery: deleteQuery}}, nil
	} else if q.drop_series_query != nil {
		dropSeriesQuery, err := parseDropSeriesQuery(query, q.drop_series_query)
		if err != nil {
			return nil, err
		}
		return []*Query{{QueryString: query, DropSeriesQuery: dropSeriesQuery}}, nil
	} else if q.drop_query != nil {
		return []*Query{&Query{QueryString: query, DropQuery: &DropQuery{Id: int(q.drop_query.id)}}}, nil
	} else if q.subscribe_query != nil {
        subscribeQuery, err := parseSubscribeQuery(q.subscribe_query)
        if err != nil {
            return nil, err
        }
        // need to do something to extract the id somehow
        return []*Query{&Query{QueryString: query, SubscribeQuery: subscribeQuery}}, nil
    }
		return []*Query{{QueryString: query, DropQuery: &DropQuery{Id: int(q.drop_query.id)}}}, nil
	}
Example #4
0
func ParseQuery(query string) ([]*Query, error) {
	queryString := C.CString(query)
	defer C.free(unsafe.Pointer(queryString))
	q := C.parse_query(queryString)
	defer C.close_query(&q)

	if q.error != nil {
		str := C.GoString(q.error.err)
		err := fmt.Errorf("Error at %d:%d. %s", q.error.line, q.error.column, str)
		return nil, err
	}

	if q.list_series_query != 0 {
		return []*Query{&Query{ListQuery: &ListQuery{Type: Series}}}, nil
	}

	if q.list_continuous_queries_query != 0 {
		return []*Query{&Query{ListQuery: &ListQuery{Type: ContinuousQueries}}}, nil
	}

	if q.select_query != nil {
		selectQuery, err := parseSelectQuery(query, q.select_query)
		if err != nil {
			return nil, err
		}

		return []*Query{&Query{SelectQuery: selectQuery}}, nil
	} else if q.delete_query != nil {
		deleteQuery, err := parseDeleteQuery(query, q.delete_query)
		if err != nil {
			return nil, err
		}
		return []*Query{&Query{DeleteQuery: deleteQuery}}, nil
	} else if q.drop_series_query != nil {
		dropSeriesQuery, err := parseDropSeriesQuery(query, q.drop_series_query)
		if err != nil {
			return nil, err
		}
		return []*Query{&Query{DropSeriesQuery: dropSeriesQuery}}, nil
	} else if q.drop_query != nil {
		fmt.Println(q.drop_query.id)
		return []*Query{&Query{DropQuery: &DropQuery{Id: int(q.drop_query.id)}}}, nil
	}
	return nil, fmt.Errorf("Unknown query type encountered")
}
Example #5
0
func ParseQuery(query string) (*Query, error) {
	queryString := C.CString(query)
	defer C.free(unsafe.Pointer(queryString))
	q := C.parse_query(queryString)
	defer C.close_query(&q)

	if q.error != nil {
		str := C.GoString(q.error.err)
		err := fmt.Errorf("Error at %d:%d. %s", q.error.line, q.error.column, str)
		return nil, err
	}

	goQuery := &Query{query, nil, nil, nil, nil, int(q.limit), q.ascending != 0, time.Unix(0, 0), time.Now()}

	var err error

	// get the column names
	goQuery.ColumnNames, err = GetValueArray(q.c)
	if err != nil {
		return nil, err
	}

	// get the from clause
	goQuery.FromClause, err = GetFromClause(q.from_clause)
	if err != nil {
		return nil, err
	}

	// get the where condition
	if q.where_condition != nil {
		goQuery.Condition, err = GetWhereCondition(q.where_condition)
		if err != nil {
			return nil, err
		}
	}

	// get the group by clause
	if q.group_by == nil {
		goQuery.groupByClause = GroupByClause{}
	} else {
		goQuery.groupByClause, err = GetValueArray(q.group_by)
		if err != nil {
			return nil, err
		}
	}

	var startTime, endTime time.Time

	goQuery.Condition, endTime, err = getTime(goQuery.GetWhereCondition(), false)
	if err != nil {
		return nil, err
	}

	if endTime.Unix() > 0 {
		goQuery.endTime = endTime
	}

	goQuery.Condition, startTime, err = getTime(goQuery.GetWhereCondition(), true)
	if err != nil {
		return nil, err
	}

	if startTime.Unix() > 0 {
		goQuery.startTime = startTime
	} else if goQuery.endTime.Unix() > 0 {
		goQuery.startTime = goQuery.endTime.Add(-1 * time.Hour)
	}

	return goQuery, nil
}