-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
partiql-planner/src/main/kotlin/org/partiql/planner/catalog/Path.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.partiql.planner.catalog | ||
|
||
import java.util.Spliterator | ||
import java.util.function.Consumer | ||
|
||
/** | ||
* The routine resolution path, accessible via PATH. | ||
*/ | ||
public class Path private constructor( | ||
private val namespaces: List<Namespace>, | ||
) : Iterable<Namespace> { | ||
|
||
public companion object { | ||
|
||
@JvmStatic | ||
public fun of(vararg namespaces: Namespace): Path = Path(namespaces.toList()) | ||
} | ||
|
||
public fun getLength(): Int { | ||
return namespaces.size | ||
} | ||
|
||
public fun isEmpty(): Boolean { | ||
return namespaces.isEmpty() | ||
} | ||
|
||
public operator fun get(index: Int): Namespace { | ||
return namespaces[index] | ||
} | ||
|
||
override fun forEach(action: Consumer<in Namespace>?) { | ||
namespaces.forEach(action) | ||
} | ||
|
||
override fun iterator(): Iterator<Namespace> { | ||
return namespaces.iterator() | ||
} | ||
|
||
override fun spliterator(): Spliterator<Namespace> { | ||
return namespaces.spliterator() | ||
} | ||
|
||
override fun toString(): String = "PATH: (${namespaces.joinToString()})" | ||
} |
64 changes: 64 additions & 0 deletions
64
partiql-planner/src/main/kotlin/org/partiql/planner/catalog/Session.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.partiql.planner.catalog | ||
|
||
/** | ||
* Session is used for authorization and name resolution. | ||
*/ | ||
public interface Session { | ||
|
||
public companion object { | ||
|
||
private val EMPTY = object : Session { | ||
override fun getIdentity(): String = "unknown" | ||
override fun getNamespace(): Namespace = Namespace.root() | ||
} | ||
|
||
@JvmStatic | ||
public fun empty(): Session = EMPTY | ||
|
||
@JvmStatic | ||
public fun builder(): Builder = Builder() | ||
} | ||
|
||
/** | ||
* Returns the caller identity as a string; accessible via CURRENT_USER. | ||
*/ | ||
public fun getIdentity(): String | ||
|
||
/** | ||
* Returns the current [Namespace]; accessible via the NAMESPACE session variable. | ||
*/ | ||
public fun getNamespace(): Namespace | ||
|
||
/** | ||
* Returns the current [Path]; accessible via the PATH and CURRENT_PATH session variables. | ||
* | ||
* Default implementation returns the current namespace. | ||
*/ | ||
public fun getPath(): Path = Path.of(getNamespace()) | ||
|
||
/** | ||
* Arbitrary session properties that may be used in planning or custom plan passes. | ||
*/ | ||
public fun getProperties(): Map<String, String> = emptyMap() | ||
|
||
/** | ||
* Java-style session builder. | ||
*/ | ||
public class Builder { | ||
|
||
private var identity: String = "unknown" | ||
private var namespace: Namespace = Namespace.root() | ||
private var properties: MutableMap<String, String> = mutableMapOf() | ||
|
||
public fun identity(identity: String): Builder = this.apply { this.identity = identity } | ||
|
||
public fun namespace(namespace: Namespace): Builder = this.apply { this.namespace = namespace } | ||
|
||
public fun property(name: String, value: String): Builder = this.apply { this.properties[name] = value } | ||
|
||
public fun build(): Session = object : Session { | ||
override fun getIdentity(): String = identity | ||
override fun getNamespace(): Namespace = namespace | ||
} | ||
} | ||
} |