From f42b2559951d307c6a7fb7a8dde2ba5081173046 Mon Sep 17 00:00:00 2001 From: Matt Hicks Date: Thu, 19 Sep 2024 13:02:33 -0500 Subject: [PATCH] Refactored Field types to be within object --- .../scala/lightdb/async/AsyncCollection.scala | 3 +- .../main/scala/lightdb/async/AsyncQuery.scala | 3 +- .../async/AsyncTransactionConvenience.scala | 3 +- build.sbt | 2 +- core/src/main/scala/lightdb/Field.scala | 28 +++++++++---------- core/src/main/scala/lightdb/Query.scala | 1 + .../main/scala/lightdb/SearchResults.scala | 1 + .../scala/lightdb/collection/Collection.scala | 3 +- .../scala/lightdb/doc/DocumentModel.scala | 3 +- .../main/scala/lightdb/facet/FacetQuery.scala | 2 +- .../scala/lightdb/store/InMemoryIndexes.scala | 3 +- .../main/scala/lightdb/store/MapStore.scala | 3 +- core/src/main/scala/lightdb/store/Store.scala | 3 +- .../lightdb/store/split/SplitStore.scala | 3 +- .../trigger/BasicCollectionTrigger.scala | 4 +-- .../lightdb/trigger/CollectionTrigger.scala | 4 +-- .../lightdb/trigger/CollectionTriggers.scala | 2 +- .../scala/lightdb/util/InMemoryIndex.scala | 3 +- .../scala/lightdb/halodb/HaloDBStore.scala | 3 +- .../scala/lightdb/lucene/LuceneStore.scala | 3 +- .../main/scala/lightdb/mapdb/MapDBStore.scala | 5 ++-- .../main/scala/lightdb/redis/RedisStore.scala | 5 ++-- .../scala/lightdb/rocksdb/RocksDBStore.scala | 3 +- sql/src/main/scala/lightdb/sql/SQLArg.scala | 3 +- sql/src/main/scala/lightdb/sql/SQLStore.scala | 4 ++- 25 files changed, 59 insertions(+), 41 deletions(-) diff --git a/async/src/main/scala/lightdb/async/AsyncCollection.scala b/async/src/main/scala/lightdb/async/AsyncCollection.scala index e42f0f1b..b2c9f4fa 100644 --- a/async/src/main/scala/lightdb/async/AsyncCollection.scala +++ b/async/src/main/scala/lightdb/async/AsyncCollection.scala @@ -1,7 +1,8 @@ package lightdb.async import cats.effect.IO -import lightdb.{Field, Id, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.collection.Collection import lightdb.doc.{Document, DocumentModel} import lightdb.transaction.Transaction diff --git a/async/src/main/scala/lightdb/async/AsyncQuery.scala b/async/src/main/scala/lightdb/async/AsyncQuery.scala index d8fb3017..4dd1b542 100644 --- a/async/src/main/scala/lightdb/async/AsyncQuery.scala +++ b/async/src/main/scala/lightdb/async/AsyncQuery.scala @@ -3,7 +3,8 @@ package lightdb.async import cats.effect.IO import fabric.Json import lightdb.aggregate.AggregateFunction -import lightdb.{Field, Id, Query, SearchResults, Sort, SortDirection, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.collection.Collection import lightdb.distance.Distance import lightdb.doc.{Document, DocumentModel} diff --git a/async/src/main/scala/lightdb/async/AsyncTransactionConvenience.scala b/async/src/main/scala/lightdb/async/AsyncTransactionConvenience.scala index f9832cf4..70a42a67 100644 --- a/async/src/main/scala/lightdb/async/AsyncTransactionConvenience.scala +++ b/async/src/main/scala/lightdb/async/AsyncTransactionConvenience.scala @@ -2,7 +2,8 @@ package lightdb.async import cats.effect.IO import lightdb.doc.{Document, DocumentModel} -import lightdb.{Field, Id, UniqueIndex} +import lightdb._ +import lightdb.Field._ case class AsyncTransactionConvenience[Doc <: Document[Doc], Model <: DocumentModel[Doc]](collection: AsyncCollection[Doc, Model]) { def insert(doc: Doc): IO[Doc] = collection.transaction { implicit transaction => diff --git a/build.sbt b/build.sbt index df16c959..1a856a3b 100644 --- a/build.sbt +++ b/build.sbt @@ -15,7 +15,7 @@ val developerURL: String = "https://matthicks.com" name := projectName ThisBuild / organization := org -ThisBuild / version := "0.13.0-SNAPSHOT" +ThisBuild / version := "0.13.0-SNAPSHOT1" ThisBuild / scalaVersion := scala213 ThisBuild / crossScalaVersions := allScalaVersions ThisBuild / scalacOptions ++= Seq("-unchecked", "-deprecation") diff --git a/core/src/main/scala/lightdb/Field.scala b/core/src/main/scala/lightdb/Field.scala index b51a2710..ff2bb56a 100644 --- a/core/src/main/scala/lightdb/Field.scala +++ b/core/src/main/scala/lightdb/Field.scala @@ -86,20 +86,6 @@ sealed class Field[Doc <: Document[Doc], V](val name: String, override def toString: String = s"Field(name = $name)" } -trait Indexed[Doc <: Document[Doc], V] extends Field[Doc, V] - -trait UniqueIndex[Doc <: Document[Doc], V] extends Indexed[Doc, V] - -trait Tokenized[Doc <: Document[Doc]] extends Indexed[Doc, String] - -class FacetField[Doc <: Document[Doc]](name: String, - get: Doc => List[FacetValue], - val hierarchical: Boolean, - val multiValued: Boolean, - val requireDimCount: Boolean) extends Field[Doc, List[FacetValue]](name, get, getRW = () => implicitly[RW[List[FacetValue]]], indexed = true) with Indexed[Doc, List[FacetValue]] { - def drillDown(path: String*): DrillDownFacetFilter[Doc] = DrillDownFacetFilter(name, path.toList) -} - object Field { val NullString: String = "||NULL||" @@ -170,4 +156,18 @@ object Field { case t: Throwable => throw new RuntimeException(s"Failure to convert $name = $s to $definition", t) } } + + trait Indexed[Doc <: Document[Doc], V] extends Field[Doc, V] + + trait UniqueIndex[Doc <: Document[Doc], V] extends Indexed[Doc, V] + + trait Tokenized[Doc <: Document[Doc]] extends Indexed[Doc, String] + + class FacetField[Doc <: Document[Doc]](name: String, + get: Doc => List[FacetValue], + val hierarchical: Boolean, + val multiValued: Boolean, + val requireDimCount: Boolean) extends Field[Doc, List[FacetValue]](name, get, getRW = () => implicitly[RW[List[FacetValue]]], indexed = true) with Indexed[Doc, List[FacetValue]] { + def drillDown(path: String*): DrillDownFacetFilter[Doc] = DrillDownFacetFilter(name, path.toList) + } } \ No newline at end of file diff --git a/core/src/main/scala/lightdb/Query.scala b/core/src/main/scala/lightdb/Query.scala index 96684098..4dea7346 100644 --- a/core/src/main/scala/lightdb/Query.scala +++ b/core/src/main/scala/lightdb/Query.scala @@ -1,6 +1,7 @@ package lightdb import fabric.Json +import lightdb.Field._ import lightdb.aggregate.{AggregateFunction, AggregateQuery} import lightdb.collection.Collection import lightdb.distance.Distance diff --git a/core/src/main/scala/lightdb/SearchResults.scala b/core/src/main/scala/lightdb/SearchResults.scala index 24ffa382..650b6ad2 100644 --- a/core/src/main/scala/lightdb/SearchResults.scala +++ b/core/src/main/scala/lightdb/SearchResults.scala @@ -1,5 +1,6 @@ package lightdb +import lightdb.Field._ import lightdb.doc.{Document, DocumentModel} import lightdb.facet.FacetResult import lightdb.transaction.Transaction diff --git a/core/src/main/scala/lightdb/collection/Collection.scala b/core/src/main/scala/lightdb/collection/Collection.scala index 5d34d102..4407b062 100644 --- a/core/src/main/scala/lightdb/collection/Collection.scala +++ b/core/src/main/scala/lightdb/collection/Collection.scala @@ -9,7 +9,8 @@ import lightdb.store.Store import lightdb.transaction.Transaction import lightdb.trigger.CollectionTriggers import lightdb.util.Initializable -import lightdb.{Id, Query, UniqueIndex} +import lightdb._ +import lightdb.Field._ import java.util.concurrent.ConcurrentHashMap import scala.jdk.CollectionConverters.IteratorHasAsScala diff --git a/core/src/main/scala/lightdb/doc/DocumentModel.scala b/core/src/main/scala/lightdb/doc/DocumentModel.scala index 6858c347..5a9ef368 100644 --- a/core/src/main/scala/lightdb/doc/DocumentModel.scala +++ b/core/src/main/scala/lightdb/doc/DocumentModel.scala @@ -4,7 +4,8 @@ import fabric.rw._ import lightdb.collection.Collection import lightdb.facet.FacetValue import lightdb.filter.FilterBuilder -import lightdb.{FacetField, Field, Id, Indexed, Tokenized, Unique, UniqueIndex} +import lightdb._ +import lightdb.Field._ import scala.language.implicitConversions diff --git a/core/src/main/scala/lightdb/facet/FacetQuery.scala b/core/src/main/scala/lightdb/facet/FacetQuery.scala index c88a043a..9bd7f957 100644 --- a/core/src/main/scala/lightdb/facet/FacetQuery.scala +++ b/core/src/main/scala/lightdb/facet/FacetQuery.scala @@ -1,6 +1,6 @@ package lightdb.facet -import lightdb.FacetField +import lightdb.Field.FacetField import lightdb.doc.Document case class FacetQuery[Doc <: Document[Doc]](field: FacetField[Doc], diff --git a/core/src/main/scala/lightdb/store/InMemoryIndexes.scala b/core/src/main/scala/lightdb/store/InMemoryIndexes.scala index 642b7cf2..f0bf133b 100644 --- a/core/src/main/scala/lightdb/store/InMemoryIndexes.scala +++ b/core/src/main/scala/lightdb/store/InMemoryIndexes.scala @@ -1,6 +1,7 @@ package lightdb.store -import lightdb.{Id, Indexed, Query, SearchResults, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.collection.Collection import lightdb.doc.{Document, DocumentModel} import lightdb.transaction.Transaction diff --git a/core/src/main/scala/lightdb/store/MapStore.scala b/core/src/main/scala/lightdb/store/MapStore.scala index a3dfee80..98c7c4a8 100644 --- a/core/src/main/scala/lightdb/store/MapStore.scala +++ b/core/src/main/scala/lightdb/store/MapStore.scala @@ -2,7 +2,8 @@ package lightdb.store import lightdb.aggregate.AggregateQuery import lightdb.collection.Collection -import lightdb.{Field, Id, LightDB, Query, SearchResults, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.doc.{Document, DocumentModel} import lightdb.materialized.MaterializedAggregate import lightdb.transaction.Transaction diff --git a/core/src/main/scala/lightdb/store/Store.scala b/core/src/main/scala/lightdb/store/Store.scala index 1e053003..6eb9143f 100644 --- a/core/src/main/scala/lightdb/store/Store.scala +++ b/core/src/main/scala/lightdb/store/Store.scala @@ -7,7 +7,8 @@ import lightdb.collection.Collection import lightdb.doc.{Document, DocumentModel} import lightdb.materialized.MaterializedAggregate import lightdb.transaction.Transaction -import lightdb.{Field, Id, Indexed, Query, SearchResults, Unique, UniqueIndex} +import lightdb._ +import lightdb.Field._ import java.io.File diff --git a/core/src/main/scala/lightdb/store/split/SplitStore.scala b/core/src/main/scala/lightdb/store/split/SplitStore.scala index 2ecf1158..1424e86f 100644 --- a/core/src/main/scala/lightdb/store/split/SplitStore.scala +++ b/core/src/main/scala/lightdb/store/split/SplitStore.scala @@ -6,7 +6,8 @@ import lightdb.doc.{Document, DocumentModel} import lightdb.materialized.MaterializedAggregate import lightdb.store.{Conversion, Store, StoreMode} import lightdb.transaction.{Transaction, TransactionKey} -import lightdb.{Field, Id, Query, SearchResults, UniqueIndex} +import lightdb._ +import lightdb.Field._ import scala.language.implicitConversions diff --git a/core/src/main/scala/lightdb/trigger/BasicCollectionTrigger.scala b/core/src/main/scala/lightdb/trigger/BasicCollectionTrigger.scala index 855e5cab..8289cf76 100644 --- a/core/src/main/scala/lightdb/trigger/BasicCollectionTrigger.scala +++ b/core/src/main/scala/lightdb/trigger/BasicCollectionTrigger.scala @@ -1,6 +1,6 @@ package lightdb.trigger -import lightdb.UniqueIndex +import lightdb.Field import lightdb.collection.Collection import lightdb.doc.{Document, DocumentModel} import lightdb.transaction.Transaction @@ -23,7 +23,7 @@ trait BasicCollectionTrigger[Doc <: Document[Doc], Model <: DocumentModel[Doc]] } } - override final def delete[V](index: UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = { + override final def delete[V](index: Field.UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = { collection.query.filter(_ => index === value).iterator.foreach(removing) } diff --git a/core/src/main/scala/lightdb/trigger/CollectionTrigger.scala b/core/src/main/scala/lightdb/trigger/CollectionTrigger.scala index 786210ca..e4119c5f 100644 --- a/core/src/main/scala/lightdb/trigger/CollectionTrigger.scala +++ b/core/src/main/scala/lightdb/trigger/CollectionTrigger.scala @@ -1,13 +1,13 @@ package lightdb.trigger -import lightdb.UniqueIndex +import lightdb.Field import lightdb.doc.Document import lightdb.transaction.Transaction trait CollectionTrigger[Doc <: Document[Doc]] { def insert(doc: Doc)(implicit transaction: Transaction[Doc]): Unit = {} def upsert(doc: Doc)(implicit transaction: Transaction[Doc]): Unit = {} - def delete[V](index: UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = {} + def delete[V](index: Field.UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = {} def truncate(): Unit = {} def dispose(): Unit = {} } \ No newline at end of file diff --git a/core/src/main/scala/lightdb/trigger/CollectionTriggers.scala b/core/src/main/scala/lightdb/trigger/CollectionTriggers.scala index d333cc14..fcaf72b6 100644 --- a/core/src/main/scala/lightdb/trigger/CollectionTriggers.scala +++ b/core/src/main/scala/lightdb/trigger/CollectionTriggers.scala @@ -1,6 +1,6 @@ package lightdb.trigger -import lightdb.UniqueIndex +import lightdb.Field.UniqueIndex import lightdb.doc.Document import lightdb.transaction.Transaction diff --git a/core/src/main/scala/lightdb/util/InMemoryIndex.scala b/core/src/main/scala/lightdb/util/InMemoryIndex.scala index 37d11005..f674d0df 100644 --- a/core/src/main/scala/lightdb/util/InMemoryIndex.scala +++ b/core/src/main/scala/lightdb/util/InMemoryIndex.scala @@ -1,6 +1,7 @@ package lightdb.util -import lightdb.{Field, Id, Indexed} +import lightdb._ +import lightdb.Field._ import lightdb.doc.Document import java.util.Comparator diff --git a/halodb/src/main/scala/lightdb/halodb/HaloDBStore.scala b/halodb/src/main/scala/lightdb/halodb/HaloDBStore.scala index de8891af..c4231903 100644 --- a/halodb/src/main/scala/lightdb/halodb/HaloDBStore.scala +++ b/halodb/src/main/scala/lightdb/halodb/HaloDBStore.scala @@ -5,7 +5,8 @@ import fabric.io.{JsonFormatter, JsonParser} import fabric.rw.{Asable, Convertible} import lightdb.aggregate.AggregateQuery import lightdb.collection.Collection -import lightdb.{Field, Id, LightDB, Query, SearchResults, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.doc.{Document, DocumentModel} import lightdb.materialized.MaterializedAggregate import lightdb.store.{Conversion, Store, StoreManager, StoreMode} diff --git a/lucene/src/main/scala/lightdb/lucene/LuceneStore.scala b/lucene/src/main/scala/lightdb/lucene/LuceneStore.scala index f178557b..612968c1 100644 --- a/lucene/src/main/scala/lightdb/lucene/LuceneStore.scala +++ b/lucene/src/main/scala/lightdb/lucene/LuceneStore.scala @@ -7,7 +7,8 @@ import fabric.rw.{Asable, Convertible} import lightdb.SortDirection.Ascending import lightdb.aggregate.{AggregateQuery, AggregateType} import lightdb.collection.Collection -import lightdb.{FacetField, Field, Id, LightDB, Query, SearchResults, Sort, SortDirection, Tokenized, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.doc.{Document, DocumentModel, JsonConversion} import lightdb.facet.{FacetResult, FacetResultValue} import lightdb.filter.{Condition, Filter} diff --git a/mapdb/src/main/scala/lightdb/mapdb/MapDBStore.scala b/mapdb/src/main/scala/lightdb/mapdb/MapDBStore.scala index 004edafe..ea3f5a12 100644 --- a/mapdb/src/main/scala/lightdb/mapdb/MapDBStore.scala +++ b/mapdb/src/main/scala/lightdb/mapdb/MapDBStore.scala @@ -1,10 +1,9 @@ package lightdb.mapdb -import fabric.io.{JsonFormatter, JsonParser} -import fabric.rw.{Asable, Convertible} import lightdb.aggregate.AggregateQuery import lightdb.collection.Collection -import lightdb.{Field, Id, LightDB, Query, SearchResults, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.doc.{Document, DocumentModel} import lightdb.materialized.MaterializedAggregate import lightdb.store.{Conversion, Store, StoreManager, StoreMode} diff --git a/redis/src/main/scala/lightdb/redis/RedisStore.scala b/redis/src/main/scala/lightdb/redis/RedisStore.scala index b992d502..d39ce77f 100644 --- a/redis/src/main/scala/lightdb/redis/RedisStore.scala +++ b/redis/src/main/scala/lightdb/redis/RedisStore.scala @@ -2,12 +2,13 @@ package lightdb.redis import lightdb.aggregate.AggregateQuery import lightdb.collection.Collection -import lightdb.{Field, Id, Query, SearchResults, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.doc.{Document, DocumentModel} import lightdb.materialized.MaterializedAggregate import lightdb.store.{Conversion, Store, StoreMode} import lightdb.transaction.{Transaction, TransactionKey} -import redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig} +import _root_.redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig} import scala.jdk.CollectionConverters.IteratorHasAsScala diff --git a/rocksdb/src/main/scala/lightdb/rocksdb/RocksDBStore.scala b/rocksdb/src/main/scala/lightdb/rocksdb/RocksDBStore.scala index c70048fb..437397d5 100644 --- a/rocksdb/src/main/scala/lightdb/rocksdb/RocksDBStore.scala +++ b/rocksdb/src/main/scala/lightdb/rocksdb/RocksDBStore.scala @@ -4,7 +4,8 @@ import fabric.io.{JsonFormatter, JsonParser} import fabric.rw.{Asable, Convertible} import lightdb.aggregate.AggregateQuery import lightdb.collection.Collection -import lightdb.{Field, Id, Query, SearchResults, UniqueIndex} +import lightdb._ +import lightdb.Field._ import lightdb.doc.{Document, DocumentModel} import lightdb.materialized.MaterializedAggregate import lightdb.store.{Conversion, Store, StoreMode} diff --git a/sql/src/main/scala/lightdb/sql/SQLArg.scala b/sql/src/main/scala/lightdb/sql/SQLArg.scala index 4f2ed7d6..6ceb33b6 100644 --- a/sql/src/main/scala/lightdb/sql/SQLArg.scala +++ b/sql/src/main/scala/lightdb/sql/SQLArg.scala @@ -6,7 +6,8 @@ import fabric.io.JsonFormatter import fabric.rw._ import lightdb.doc.Document import lightdb.spatial.Geo -import lightdb.{Field, Id, Tokenized} +import lightdb._ +import lightdb.Field._ import java.sql.{JDBCType, PreparedStatement, SQLType, Types} diff --git a/sql/src/main/scala/lightdb/sql/SQLStore.scala b/sql/src/main/scala/lightdb/sql/SQLStore.scala index 48ef7ec9..57f7dfc3 100644 --- a/sql/src/main/scala/lightdb/sql/SQLStore.scala +++ b/sql/src/main/scala/lightdb/sql/SQLStore.scala @@ -15,7 +15,8 @@ import lightdb.sql.connect.ConnectionManager import lightdb.store.{Conversion, Store, StoreMode} import lightdb.transaction.{Transaction, TransactionKey} import lightdb.util.ActionIterator -import lightdb.{Field, Id, Indexed, Query, SearchResults, Sort, SortDirection, Tokenized, UniqueIndex} +import lightdb._ +import lightdb.Field._ import java.sql.{Connection, PreparedStatement, ResultSet} import scala.language.implicitConversions @@ -491,6 +492,7 @@ abstract class SQLStore[Doc <: Document[Doc], Model <: DocumentModel[Doc]] exten throw new UnsupportedOperationException("Distance filtering not supported in SQL!") private def filter2Part(f: Filter[Doc]): SQLPart = f match { + case f: Filter.DrillDownFacetFilter[Doc] => throw new UnsupportedOperationException(s"SQLStore does not support Facets: $f") case f: Filter.Equals[Doc, _] if f.field(collection.model).isArr => val values = f.getJson(collection.model).asVector val parts = values.map { json =>