Skip to content

Commit

Permalink
Begin passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Jul 18, 2024
1 parent f64aa27 commit 5879f3a
Show file tree
Hide file tree
Showing 16 changed files with 670 additions and 602 deletions.
16 changes: 7 additions & 9 deletions partiql-planner/api/partiql-planner.api
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public final class org/partiql/planner/catalog/Catalogs$DefaultImpls {
public final class org/partiql/planner/catalog/Identifier : java/lang/Iterable, kotlin/jvm/internal/markers/KMappedMarker {
public static final field Companion Lorg/partiql/planner/catalog/Identifier$Companion;
public synthetic fun <init> ([Lorg/partiql/planner/catalog/Identifier$Part;Lorg/partiql/planner/catalog/Identifier$Part;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun append (Lorg/partiql/planner/catalog/Identifier;)Lorg/partiql/planner/catalog/Identifier;
public final fun append ([Lorg/partiql/planner/catalog/Identifier$Part;)Lorg/partiql/planner/catalog/Identifier;
public static final fun delimited (Ljava/lang/String;)Lorg/partiql/planner/catalog/Identifier;
public static final fun delimited (Ljava/util/Collection;)Lorg/partiql/planner/catalog/Identifier;
public static final fun delimited ([Ljava/lang/String;)Lorg/partiql/planner/catalog/Identifier;
Expand All @@ -91,11 +93,8 @@ public final class org/partiql/planner/catalog/Identifier : java/lang/Iterable,
public fun hashCode ()I
public fun iterator ()Ljava/util/Iterator;
public final fun matches (Ljava/lang/String;Z)Z
public final fun matches (Lorg/partiql/planner/catalog/Identifier;Z)Z
public static synthetic fun matches$default (Lorg/partiql/planner/catalog/Identifier;Ljava/lang/String;ZILjava/lang/Object;)Z
public static synthetic fun matches$default (Lorg/partiql/planner/catalog/Identifier;Lorg/partiql/planner/catalog/Identifier;ZILjava/lang/Object;)Z
public static final fun of (Ljava/util/Collection;)Lorg/partiql/planner/catalog/Identifier;
public static final fun of (Lorg/partiql/planner/catalog/Identifier$Part;)Lorg/partiql/planner/catalog/Identifier;
public static final fun of ([Lorg/partiql/planner/catalog/Identifier$Part;)Lorg/partiql/planner/catalog/Identifier;
public static final fun regular (Ljava/lang/String;)Lorg/partiql/planner/catalog/Identifier;
public fun spliterator ()Ljava/util/Spliterator;
Expand All @@ -107,7 +106,6 @@ public final class org/partiql/planner/catalog/Identifier$Companion {
public final fun delimited (Ljava/util/Collection;)Lorg/partiql/planner/catalog/Identifier;
public final fun delimited ([Ljava/lang/String;)Lorg/partiql/planner/catalog/Identifier;
public final fun of (Ljava/util/Collection;)Lorg/partiql/planner/catalog/Identifier;
public final fun of (Lorg/partiql/planner/catalog/Identifier$Part;)Lorg/partiql/planner/catalog/Identifier;
public final fun of ([Lorg/partiql/planner/catalog/Identifier$Part;)Lorg/partiql/planner/catalog/Identifier;
public final fun regular (Ljava/lang/String;)Lorg/partiql/planner/catalog/Identifier;
}
Expand All @@ -121,7 +119,6 @@ public final class org/partiql/planner/catalog/Identifier$Part {
public fun hashCode ()I
public final fun isRegular ()Z
public final fun matches (Ljava/lang/String;)Z
public final fun matches (Lorg/partiql/planner/catalog/Identifier$Part;)Z
public static final fun regular (Ljava/lang/String;)Lorg/partiql/planner/catalog/Identifier$Part;
public fun toString ()Ljava/lang/String;
}
Expand Down Expand Up @@ -155,7 +152,8 @@ public final class org/partiql/planner/catalog/Name$Companion {
public final class org/partiql/planner/catalog/Namespace : java/lang/Iterable, kotlin/jvm/internal/markers/KMappedMarker {
public static final field Companion Lorg/partiql/planner/catalog/Namespace$Companion;
public synthetic fun <init> ([Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun concat ([Ljava/lang/String;)Lorg/partiql/planner/catalog/Namespace;
public final fun append ([Ljava/lang/String;)Lorg/partiql/planner/catalog/Namespace;
public final fun asIdentifier ()Lorg/partiql/planner/catalog/Identifier;
public fun equals (Ljava/lang/Object;)Z
public fun forEach (Ljava/util/function/Consumer;)V
public final fun get (I)Ljava/lang/String;
Expand All @@ -171,9 +169,9 @@ public final class org/partiql/planner/catalog/Namespace : java/lang/Iterable, k
}

public final class org/partiql/planner/catalog/Namespace$Companion {
public final fun empty ()Lorg/partiql/planner/catalog/Namespace;
public final fun of (Ljava/util/Collection;)Lorg/partiql/planner/catalog/Namespace;
public final fun of ([Ljava/lang/String;)Lorg/partiql/planner/catalog/Namespace;
public final fun root ()Lorg/partiql/planner/catalog/Namespace;
}

public final class org/partiql/planner/catalog/Path : java/lang/Iterable, kotlin/jvm/internal/markers/KMappedMarker {
Expand Down Expand Up @@ -318,8 +316,8 @@ public final class org/partiql/planner/catalog/Table$DefaultImpls {
}

public final class org/partiql/planner/catalog/Table$Handle {
public final field namespace Lorg/partiql/planner/catalog/Namespace;
public final field name Lorg/partiql/planner/catalog/Name;
public final field table Lorg/partiql/planner/catalog/Table;
public fun <init> (Lorg/partiql/planner/catalog/Namespace;Lorg/partiql/planner/catalog/Table;)V
public fun <init> (Lorg/partiql/planner/catalog/Name;Lorg/partiql/planner/catalog/Table;)V
}

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface Catalog {
/**
* List top-level tables.
*/
public fun listTables(session: Session): Collection<Name> = listTables(session, Namespace.root())
public fun listTables(session: Session): Collection<Name> = listTables(session, Namespace.empty())

/**
* List all tables under this namespace.
Expand All @@ -50,7 +50,7 @@ public interface Catalog {
/**
* List top-level namespaces from the catalog.
*/
public fun listNamespaces(session: Session): Collection<Namespace> = listNamespaces(session, Namespace.root())
public fun listNamespaces(session: Session): Collection<Namespace> = listNamespaces(session, Namespace.empty())

/**
* List all child namespaces from the namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface Catalogs {
*/
public fun get(name: String, ignoreCase: Boolean = false): Catalog? {
val default = default()
return if (name.equals(default.getName(), ignoreCase = true)) {
return if (name.equals(default.getName(), ignoreCase)) {
default
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public class Identifier private constructor(
return getParts().spliterator()
}

/**
* Returns a new identifier with the given parts appended.
*/
public fun append(other: Identifier): Identifier {
return of(this.toList() + other.toList())
}

/**
* Returns a new identifier with the given parts appended.
*/
public fun append(vararg parts: Part): Identifier {
return of(this.toList() + parts)
}

/**
* Compares this identifier to string, possibly ignoring case.
*/
Expand All @@ -71,32 +85,6 @@ public class Identifier private constructor(
}
}

/**
* Compares one identifier to another, possibly ignoring case.
*/
public fun matches(other: Identifier, ignoreCase: Boolean = false): Boolean {
//
if (this.qualifier.size != other.qualifier.size) {
return false
}
// Compare identifier
if (ignoreCase && !(this.identifier.matches(other.identifier))) {
return false
} else if (this.identifier != other.identifier) {
return false
}
for (i in this.qualifier.indices) {
val lhs = this.qualifier[i]
val rhs = other.qualifier[i]
if (ignoreCase && !lhs.matches(rhs)) {
return false
} else if (lhs != rhs) {
return false
}
}
return true
}

/**
* Compares the case-preserved text of two identifiers — that is case-sensitive equality.
*/
Expand Down Expand Up @@ -160,13 +148,6 @@ public class Identifier private constructor(
return this.text.equals(other, ignoreCase = this.regular)
}

/**
* Compares two identifiers, ignoring case iff at least one identifier is non-delimited.
*/
public fun matches(other: Part): Boolean {
return this.text.equals(other.text, ignoreCase = (this.regular || other.regular))
}

/**
* Compares the case-preserved text of two identifiers — that is case-sensitive equality.
*/
Expand All @@ -191,8 +172,8 @@ public class Identifier private constructor(
* Return the identifier as a SQL string.
*/
override fun toString(): String = when (regular) {
true -> "\"${text}\""
false -> text
true -> text
false -> "\"${text}\""
}

public companion object {
Expand All @@ -213,9 +194,6 @@ public class Identifier private constructor(
@JvmStatic
public fun delimited(text: String): Identifier = Identifier(emptyArray(), Part.delimited(text))

@JvmStatic
public fun of(part: Part): Identifier = Identifier(emptyArray(), part)

@JvmStatic
public fun of(vararg parts: Part): Identifier = of(parts.toList())

Expand All @@ -224,7 +202,7 @@ public class Identifier private constructor(
if (parts.isEmpty()) {
error("Cannot create an identifier with no parts")
}
val qualifier = parts.drop(1).toTypedArray()
val qualifier = parts.take(parts.size - 1).toTypedArray()
val identifier = parts.last()
return Identifier(qualifier, identifier)
}
Expand All @@ -237,7 +215,7 @@ public class Identifier private constructor(
if (parts.isEmpty()) {
error("Cannot create an identifier with no parts")
}
val qualifier = parts.drop(1).map { Part.delimited(it) }.toTypedArray()
val qualifier = parts.take(parts.size - 1).map { Part.delimited(it) }.toTypedArray()
val identifier = Part.delimited(parts.last())
return Identifier(qualifier, identifier)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Name(
*/
private fun getParts(): List<String> {
val parts = mutableListOf<String>()
parts.addAll(namespace.getLevels())
parts.addAll(namespace)
parts.add(name)
return parts
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public class Name(
@JvmStatic
public fun of(names: Collection<String>): Name {
assert(names.size > 0) { "Cannot create an empty name" }
val namespace = Namespace.of(names.drop(1))
val namespace = Namespace.of(names.take(names.size - 1))
val name = names.last()
return Name(namespace, name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class Namespace private constructor(
return levels.isEmpty()
}

public fun asIdentifier(): Identifier {
return Identifier.delimited(*levels)
}

public operator fun get(index: Int): String {
return levels[index]
}
Expand All @@ -52,7 +56,7 @@ public class Namespace private constructor(
return levels.contentEquals((other as Namespace).levels)
}

public fun concat(vararg levels: String): Namespace {
public fun append(vararg levels: String): Namespace {
return Namespace(this.levels + levels)
}

Expand All @@ -67,27 +71,30 @@ public class Namespace private constructor(
* Return the SQL identifier representation of this namespace.
*/
public override fun toString(): String {
if (isEmpty()) {
return ""
}
return Identifier.delimited(*levels).toString()
}

public companion object {

private val ROOT = Namespace(emptyArray())
private val EMPTY = Namespace(emptyArray())

public fun root(): Namespace = ROOT
public fun empty(): Namespace = EMPTY

@JvmStatic
public fun of(vararg levels: String): Namespace {
if (levels.isEmpty()) {
return root()
return empty()
}
return Namespace(arrayOf(*levels))
}

@JvmStatic
public fun of(levels: Collection<String>): Namespace {
if (levels.isEmpty()) {
return root()
return empty()
}
return Namespace(levels.toTypedArray())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface Session {
public fun empty(catalog: String): Session = object : Session {
override fun getIdentity(): String = "unknown"
override fun getCatalog(): String = catalog
override fun getNamespace(): Namespace = Namespace.root()
override fun getNamespace(): Namespace = Namespace.empty()
}

@JvmStatic
Expand All @@ -58,7 +58,7 @@ public interface Session {

private var identity: String = "unknown"
private var catalog: String? = null
private var namespace: Namespace = Namespace.root()
private var namespace: Namespace = Namespace.empty()
private var properties: MutableMap<String, String> = mutableMapOf()

public fun identity(identity: String): Builder {
Expand All @@ -82,6 +82,11 @@ public interface Session {
}

public fun build(): Session = object : Session {

init {
require(catalog != null) { "Session catalog must be set" }
}

override fun getIdentity(): String = identity
override fun getCatalog(): String = catalog!!
override fun getNamespace(): Namespace = namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import org.partiql.types.PType
public interface Table {

/**
* Handle holds both a table and its namespace within its respective catalog.
* Handle holds both a table and its resolved name within its respective catalog.
*
* Note: This replaces ConnectorObjectHandle from versions < 1.0
*/
public class Handle(
@JvmField public val namespace: Namespace,
@JvmField public val name: Name,
@JvmField public val table: Table,
)

Expand Down
Loading

0 comments on commit 5879f3a

Please sign in to comment.