Esempio n. 1
0
func (this *NNF) VisitFunction(expr expression.Function) (interface{}, error) {
	var exp expression.Expression = expr

	switch expr := expr.(type) {
	case *expression.IsBoolean:
		exp = expression.NewLE(expr.Operand(), expression.TRUE_EXPR)
	case *expression.IsNumber:
		exp = expression.NewAnd(
			expression.NewGT(expr.Operand(), expression.TRUE_EXPR),
			expression.NewLT(expr.Operand(), expression.EMPTY_STRING_EXPR))
	case *expression.IsString:
		exp = expression.NewAnd(
			expression.NewGE(expr.Operand(), expression.EMPTY_STRING_EXPR),
			expression.NewLT(expr.Operand(), expression.EMPTY_ARRAY_EXPR))
	case *expression.IsArray:
		exp = expression.NewAnd(
			expression.NewGE(expr.Operand(), expression.EMPTY_ARRAY_EXPR),
			expression.NewLT(expr.Operand(), _EMPTY_OBJECT_EXPR))
	case *expression.IsObject:
		// Not equivalent to IS OBJECT. Includes BINARY values.
		exp = expression.NewGE(expr.Operand(), _EMPTY_OBJECT_EXPR)
	}

	return exp, exp.MapChildren(this)
}
Esempio n. 2
0
// Function
func (this *sargableFactory) VisitFunction(expr expression.Function) (interface{}, error) {
	switch expr := expr.(type) {
	case *expression.RegexpLike:
		return newSargableLike(expr, expr.Regexp()), nil
	}

	return newSargableDefault(expr), nil
}
Esempio n. 3
0
// Function
func (this *JSConverter) VisitFunction(expr expression.Function) (interface{}, error) {
	var buf bytes.Buffer

	functionExpr := &funcExpr{operands: list.New()}

	buf.WriteString("(")
	var nopush bool
	var pushOperands bool

	switch strings.ToLower(expr.Name()) {
	case "lower":
		functionExpr.name = ".toLowerCase()"
		this.stack.Push(functionExpr)
	case "upper":
		functionExpr.name = ".toUpperCase()"
		this.stack.Push(functionExpr)
	case "length":
		functionExpr.name = ".length"
		this.stack.Push(functionExpr)
	case "str_to_millis":
		fallthrough
	case "millis":
		nopush = true
		buf.WriteString("Date.parse(")
	case "contains":
		functionExpr.name = ".indexOf("
		this.stack.Push(functionExpr)
		pushOperands = true
	case "substr":
		functionExpr.name = ".substring("
		this.stack.Push(functionExpr)
		pushOperands = true
	case "now_millis":
		buf.WriteString("Date.now().toString()")
	default:
		nopush = true
		buf.WriteString(expr.Name())
		buf.WriteString("(")
	}

	var firstOp expression.Expression

	for i, op := range expr.Operands() {
		if pushOperands == true {

			if i == 0 {
				firstOp = op
				continue
			} else {
				functionExpr.operands.PushBack(op)
			}

		} else {
			if i > 0 {
				buf.WriteString(", ")
			}

			if op == nil {
				buf.WriteString("*") // for count(*)
			} else {
				buf.WriteString(this.Visit(op))
			}
		}
	}

	if firstOp != nil {
		buf.WriteString(this.Visit(firstOp))
	}

	if nopush == true {
		buf.WriteString("))")
	} else {
		buf.WriteString(")")
	}

	return buf.String(), nil
}