Skip to content

Commit

Permalink
Adds logical path operators
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell committed Aug 28, 2024
1 parent 8bac57c commit 71b8255
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ import org.partiql.plan.v1.operator.rex.RexCoalesce
import org.partiql.plan.v1.operator.rex.RexError
import org.partiql.plan.v1.operator.rex.RexLit
import org.partiql.plan.v1.operator.rex.RexMissing
import org.partiql.plan.v1.operator.rex.RexPath
import org.partiql.plan.v1.operator.rex.RexPathIndex
import org.partiql.plan.v1.operator.rex.RexPathKey
import org.partiql.plan.v1.operator.rex.RexPathSymbol
import org.partiql.plan.v1.operator.rex.RexPivot
import org.partiql.plan.v1.operator.rex.RexSelect
import org.partiql.plan.v1.operator.rex.RexSpread
Expand Down Expand Up @@ -309,22 +311,22 @@ internal class SqlCompiler(
return ExprMissing(unknown)
}

override fun visitPathIndex(rex: RexPath.Index, ctx: Unit): Operator.Expr {
val root = compile(rex.getRoot(), ctx)
override fun visitPathIndex(rex: RexPathIndex, ctx: Unit): Operator.Expr {
val operand = compile(rex.getOperand(), ctx)
val index = compile(rex.getIndex(), ctx)
return ExprPathIndex(root, index)
return ExprPathIndex(operand, index)
}

override fun visitPathKey(rex: RexPath.Key, ctx: Unit): Operator.Expr {
val root = compile(rex.getRoot(), ctx)
override fun visitPathKey(rex: RexPathKey, ctx: Unit): Operator.Expr {
val operand = compile(rex.getOperand(), ctx)
val key = compile(rex.getKey(), ctx)
return ExprPathKey(root, key)
return ExprPathKey(operand, key)
}

override fun visitPathSymbol(rex: RexPath.Symbol, ctx: Unit): Operator.Expr {
val root = compile(rex.getRoot(), ctx)
override fun visitPathSymbol(rex: RexPathSymbol, ctx: Unit): Operator.Expr {
val operand = compile(rex.getOperand(), ctx)
val symbol = rex.getSymbol()
return ExprPathSymbol(root, symbol)
return ExprPathSymbol(operand, symbol)
}

override fun visitPivot(rex: RexPivot, ctx: Unit): Operator.Expr {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ import org.partiql.plan.v1.operator.rex.RexLit
import org.partiql.plan.v1.operator.rex.RexLitImpl
import org.partiql.plan.v1.operator.rex.RexMissing
import org.partiql.plan.v1.operator.rex.RexMissingImpl
import org.partiql.plan.v1.operator.rex.RexPathIndex
import org.partiql.plan.v1.operator.rex.RexPathIndexImpl
import org.partiql.plan.v1.operator.rex.RexPathKey
import org.partiql.plan.v1.operator.rex.RexPathKeyImpl
import org.partiql.plan.v1.operator.rex.RexPathSymbol
import org.partiql.plan.v1.operator.rex.RexPathSymbolImpl
import org.partiql.plan.v1.operator.rex.RexPivot
import org.partiql.plan.v1.operator.rex.RexPivotImpl
import org.partiql.plan.v1.operator.rex.RexSelect
Expand Down Expand Up @@ -402,7 +408,32 @@ public interface PlanFactory {
*/
public fun rexLit(value: Datum): RexLit = RexLitImpl(value)

// TODO PATHS
/**
* Create a [RexPathIndex] instance.
*
* @param operand
* @param index
* @return
*/
public fun rexPathIndex(operand: Rex, index: Rex): RexPathIndex = RexPathIndexImpl(operand, index)

/**
* Create a [RexPathKey] instance.
*
* @param operand
* @param key
* @return
*/
public fun rexPathKey(operand: Rex, key: Rex): RexPathKey = RexPathKeyImpl(operand, key)

/**
* Create a [RexPathSymbol] instance.
*
* @param operand
* @param symbol
* @return
*/
public fun rexPathSymbol(operand: Rex, symbol: String): RexPathSymbol = RexPathSymbolImpl(operand, symbol)

/**
* Create a [RexPivot] instance.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.partiql.plan.v1.operator.rex

import org.partiql.types.PType

/**
* Logical path index operator.
*/
public interface RexPathIndex : Rex {

public fun getOperand(): Rex

public fun getIndex(): Rex

override fun <R, C> accept(visitor: RexVisitor<R, C>, ctx: C): R = visitor.visitPathIndex(this, ctx)
}

/**
* Standard internal implementation for [RexPathIndex].
*/
internal class RexPathIndexImpl(root: Rex, index: Rex) : RexPathIndex {

// DO NOT USE FINAL
private var _root = root
private var _index = index

override fun getOperand() = _root

override fun getIndex() = _index

override fun getType(): PType {
TODO("Not yet implemented")
}

override fun getChildren(): Collection<Rex> = listOf(_root, _index)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.partiql.plan.v1.operator.rex

import org.partiql.types.PType

/**
* Logical operator for path lookup by key.
*/
public interface RexPathKey : Rex {

public fun getOperand(): Rex

public fun getKey(): Rex

override fun <R, C> accept(visitor: RexVisitor<R, C>, ctx: C): R = visitor.visitPathKey(this, ctx)
}

/**
* Standard internal implementation for [RexPathKey].
*/
internal class RexPathKeyImpl(root: Rex, key: Rex) : RexPathKey {

// DO NOT USE FINAL
private var _root = root
private var _key = key

override fun getOperand() = _root

override fun getKey() = _key

override fun getType(): PType {
TODO("Not yet implemented")
}

override fun getChildren(): Collection<Rex> = listOf(_root, _key)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.partiql.plan.v1.operator.rex

import org.partiql.types.PType

/**
* Logical operator for path lookup by symbol.
*/
public interface RexPathSymbol : Rex {

public fun getOperand(): Rex

public fun getSymbol(): String

override fun <R, C> accept(visitor: RexVisitor<R, C>, ctx: C): R = visitor.visitPathSymbol(this, ctx)
}

/**
* Standard internal implementation for [RexPathSymbol].
*/
internal class RexPathSymbolImpl(root: Rex, symbol: String) : RexPathSymbol {

// DO NOT USE FINAL
private var _root = root
private var _symbol = symbol

override fun getOperand() = _root

override fun getSymbol() = _symbol

override fun getType(): PType {
TODO("Not yet implemented")
}

override fun getChildren(): Collection<Rex> = listOf(_root)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ public interface RexVisitor<R, C> {

public fun visitMissing(rex: RexMissing, ctx: C): R = defaultVisit(rex, ctx)

public fun visitPath(rex: RexPath, ctx: C): R = rex.accept(this, ctx)
public fun visitPathIndex(rex: RexPathIndex, ctx: C): R = defaultVisit(rex, ctx)

public fun visitPathIndex(rex: RexPath.Index, ctx: C): R = defaultVisit(rex, ctx)
public fun visitPathKey(rex: RexPathKey, ctx: C): R = defaultVisit(rex, ctx)

public fun visitPathKey(rex: RexPath.Key, ctx: C): R = defaultVisit(rex, ctx)

public fun visitPathSymbol(rex: RexPath.Symbol, ctx: C): R = defaultVisit(rex, ctx)
public fun visitPathSymbol(rex: RexPathSymbol, ctx: C): R = defaultVisit(rex, ctx)

public fun visitPivot(rex: RexPivot, ctx: C): R = defaultVisit(rex, ctx)

Expand Down

0 comments on commit 71b8255

Please sign in to comment.