common/elasticsearch/esql/cadenceDevReadme.md
Currently Cadence is using elasticsql to translate sql query. However it only support up to ES V2.x while Cadence is using ES V6.x. Beyond that, Cadence has some specific requirements that not supported by elasticsql yet.
Current Cadence query request processing steps are listed below:
ESQL aims at dealing all these addtional processing steps and providing an api to generate DSL in one step for visibility usage in Cadence.
ESQL has convert functions specific for cadence usage. Please refer to cadencesql.go. Below shows an example.
Attention: to use cadence version api, SetCadence() must be called at initialzation.
sql := "SELECT colA FROM myTable WHERE colB < 10 AND dateTime = '2015-01-01T02:59:59Z'"
domainID := "CadenceSampleDomain"
// custom policy that change colName like "col.." to "myCol.."
func myKeyFilter(colName string) bool {
return strings.HasPrefix(colName, "col")
}
func myKeyProcess(colName string) (string, error) {
return "myCol"+colName[3:], nil
}
// custom policy that convert formatted time string to unix nano
func myValueFilter(colName string) bool {
return strings.Contains(colName, "Time") || strings.Contains(colName, "time")
}
func myValueProcess(timeStr string) (string, error) {
// convert formatted time string to unix nano integer
parsedTime, _ := time.Parse(defaultDateTimeFormat, timeStr)
return fmt.Sprintf("%v", parsedTime.UnixNano()), nil
}
// with the 2 policies , converted dsl is equivalent to
// "SELECT myColA FROM myTable WHERE myColB < 10 AND dateTime = '1561678568048000000'
// in which the time is in unix nano format
e := NewESql()
e.SetCadence()
e.ProcessQueryKey(myKeyFilter, myKeyProcess) // set up filtering policy
e.ProcessQueryValue(myValueFilter, myValueProcess) // set up process policy
dsl, _, err := e.ConvertPrettyCadence(sql, domainID) // convert sql to dsl
if err == nil {
fmt.Println(dsl)
}
To setup local testing environment:
./bin/helloworld -m worker under cadence directory.