Commit 9cc1039e authored by Paul Asmuth's avatar Paul Asmuth
Browse files

match symbol names case-insensitively

parent 41cd58fa
Loading
Loading
Loading
Loading
+34 −6
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2011-2014 Paul Asmuth, Google Inc.
 *   Copyright (c) 2014 Paul Asmuth, Google Inc.
 *
 * FnordMetric is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License v3.0. You should have received a
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

#include <algorithm>
#include <stdlib.h>
#include <assert.h>
#include <string>
@@ -20,7 +20,17 @@ namespace query {
void SymbolTable::registerSymbol(
    const std::string& symbol,
    void (*method)(void*, int, SValue*, SValue*)) {
  symbols_.emplace(std::make_pair(symbol, SymbolTableEntry(symbol, method)));
  std::string symbol_downcase = symbol;
  std::transform(
      symbol_downcase.begin(),
      symbol_downcase.end(),
      symbol_downcase.begin(),
      ::tolower);

  symbols_.emplace(
      std::make_pair(
          symbol_downcase,
          SymbolTableEntry(symbol_downcase, method)));
}

void SymbolTable::registerSymbol(
@@ -28,15 +38,33 @@ void SymbolTable::registerSymbol(
    void (*method)(void*, int, SValue*, SValue*),
    size_t scratchpad_size,
    void (*free_method)(void*)) {
  std::string symbol_downcase = symbol;
  std::transform(
      symbol_downcase.begin(),
      symbol_downcase.end(),
      symbol_downcase.begin(),
      ::tolower);

  symbols_.emplace(
      std::make_pair(
          symbol,
          SymbolTableEntry(symbol, method, scratchpad_size, free_method)));
          symbol_downcase,
          SymbolTableEntry(
              symbol_downcase,
              method,
              scratchpad_size,
              free_method)));
}

SymbolTableEntry const* SymbolTable::lookupSymbol(const std::string& symbol)
    const {
  auto iter = symbols_.find(symbol);
  std::string symbol_downcase = symbol;
  std::transform(
      symbol_downcase.begin(),
      symbol_downcase.end(),
      symbol_downcase.begin(),
      ::tolower);

  auto iter = symbols_.find(symbol_downcase);

  if (iter == symbols_.end()) {
    RAISE(kRuntimeError, "symbol not found: %s", symbol.c_str());
+10 −0
Original line number Diff line number Diff line
@@ -918,6 +918,16 @@ TEST_CASE(SQLTest, TestSimpleAggregateFromCSV, [] () {
  EXPECT_EQ(std::stof(results->getRow(0)[0]), 74209240);
});

TEST_CASE(SQLTest, TestCaseInsensitiveFunctionNames, [] () {
  auto results = executeTestQuery(
      "  SELECT"
      "    sUM(gbp) as global_gbp"
      "  FROM"
      "    gbp_per_country;");

  EXPECT_EQ(std::stof(results->getRow(0)[0]), 74209240);
});

TEST_CASE(SQLTest, TestSimpleOrderByAsc, [] () {
  auto results = executeTestQuery(
      "  SELECT"
+7 −8
Original line number Diff line number Diff line
@@ -13,14 +13,6 @@
    - finish http api 
    - group over doc: GROUP OVER TIMEWINDOW(time_window, step) oder so

[ SQL ]
    - match function names case-insensitively
    - sql time helpers (1hour, etc)
    ---
    - support red/green/blue/hex colors
    - round fn
    - functions: round, mean, max/min, percentile, delta,  

[ frontend ]
    - clean up sql result view
    - metric overview page
@@ -33,6 +25,11 @@
    - compare with yesterday in metric preview widget
    - metric preview widget: auto refresh (on/off)

[ SQL ]
    - support hex colors
    - round fn
    - functions: round, mean, max/min, percentile, delta, 

[ release ]
    - svg: escape series names, labels!
    - inline libev
@@ -47,6 +44,8 @@
    - do I need an external database

[ feature q ]
    - sql time helpers (1hour, etc)
    - support red/green/blue colors
    - max threads in takscheduler?
    - functions: variance, stddev, nth_derivate,
    - union