Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Commit

Permalink
merging #14 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SteamShon committed May 20, 2015
2 parents 4f4608b + 52f2717 commit 1f96796
Show file tree
Hide file tree
Showing 18 changed files with 374 additions and 379 deletions.
10 changes: 8 additions & 2 deletions app/com/daumkakao/s2graph/rest/config/Config.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.daumkakao.s2graph.rest.config

import java.util.concurrent.TimeUnit
import com.codahale.metrics.{Metric, ConsoleReporter, MetricRegistry}
import com.codahale.metrics.{Slf4jReporter, Metric, ConsoleReporter, MetricRegistry}
import org.slf4j.LoggerFactory
import play.api.{Play, Logger}

object Config {
Expand Down Expand Up @@ -32,10 +33,15 @@ object Config {

trait Instrumented extends nl.grons.metrics.scala.InstrumentedBuilder {
val metricRegistry: MetricRegistry = Config.metricRegistry
val consoleReporter = ConsoleReporter.forRegistry(metricRegistry)
val reporter = Slf4jReporter.forRegistry(metricRegistry)
.outputTo(LoggerFactory.getLogger(classOf[Instrumented]))
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build()
// val consoleReporter = ConsoleReporter.forRegistry(metricRegistry)
// .convertRatesTo(TimeUnit.SECONDS)
// .convertDurationsTo(TimeUnit.MILLISECONDS)
// .build()

val stats = new collection.mutable.HashMap[String, Metric]

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ApplicationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object ApplicationController extends Controller with Instrumented {
var connectionOption = CONNECTION -> "Keep-Alive"
var keepAliveOption = "Keep-Alive" -> "timeout=5, max=100"

consoleReporter.start(10, TimeUnit.SECONDS)
reporter.start(10, TimeUnit.SECONDS)

def updateHealthCheck(isHealthy: Boolean) = Action { request =>
this.isHealthy = isHealthy
Expand Down
53 changes: 0 additions & 53 deletions app/controllers/RequestParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,59 +84,6 @@ trait RequestParser extends JSONParser {
WhereParser(label).parse(where)
}
}
case class WhereParser(label: Label) extends JavaTokenParsers with JSONParser {

val metaProps = label.metaPropsInvMap ++ Map(LabelMeta.from.name -> LabelMeta.from, LabelMeta.to.name -> LabelMeta.to)

def where: Parser[Where] = rep(clause) ^^ (Where(_))

def clause: Parser[Clause] = (predicate | parens) * (
"and" ^^^ { (a: Clause, b: Clause) => And(a, b) } |
"or" ^^^ { (a: Clause, b: Clause) => Or(a, b) })

def parens: Parser[Clause] = "(" ~> clause <~ ")"

def boolean = ("true" ^^^ (true) | "false" ^^^ (false))

/** floating point is not supported yet **/
def predicate = (
(ident ~ "=" ~ ident | ident ~ "=" ~ decimalNumber | ident ~ "=" ~ stringLiteral) ^^ {
case f ~ "=" ~ s =>
metaProps.get(f) match {
case None => throw new RuntimeException(s"where clause contains not existing property name: $f")
case Some(metaProp) =>
Equal(metaProp.seq, toInnerVal(s, metaProp.dataType))
}

}
| (ident ~ "between" ~ ident ~ "and" ~ ident | ident ~ "between" ~ decimalNumber ~ "and" ~ decimalNumber
| ident ~ "between" ~ stringLiteral ~ "and" ~ stringLiteral) ^^ {
case f ~ "between" ~ minV ~ "and" ~ maxV =>
metaProps.get(f) match {
case None => throw new RuntimeException(s"where clause contains not existing property name: $f")
case Some(metaProp) =>
Between(metaProp.seq, toInnerVal(minV, metaProp.dataType), toInnerVal(maxV, metaProp.dataType))
}
}
| (ident ~ "in" ~ "(" ~ rep(ident | decimalNumber | stringLiteral | "true" | "false" | ",") ~ ")") ^^ {
case f ~ "in" ~ "(" ~ vals ~ ")" =>
metaProps.get(f) match {
case None => throw new RuntimeException(s"where clause contains not existing property name: $f")
case Some(metaProp) =>
val values = vals.filter(v => v != ",").map { v =>
toInnerVal(v, metaProp.dataType)
}
IN(metaProp.seq, values.toSet)
}
})

def parse(sql: String): Option[Where] = {
parseAll(where, sql) match {
case Success(r, q) => Some(r)
case x => println(x); None
}
}
}

def toQuery(jsValue: JsValue, isEdgeQuery: Boolean = true): Query = {
try {
Expand Down
Loading

0 comments on commit 1f96796

Please sign in to comment.