Skip to content

Replace SinkStorageReader and SinkStorageWriter with VirtualDocument[Tuple] - #3024

Merged
bobbai00 merged 18 commits into
masterfrom
jiadong-unify-storage-api
Dec 9, 2024
Merged

bobbai00 merged 18 commits into
masterfrom
jiadong-unify-storage-api

Conversation

@bobbai00

@bobbai00 bobbai00 commented Nov 9, 2024 •

Copy link
Copy Markdown
Contributor

This PR removes the SinkStorageReader and SinkStorageWriter, and substitute it with VirtualDocument[Tuple]

1. Recap on SinkStorage and VirtualDocument

SinkStorage is one kinds of storage specialized for Tuple storage. It relies on the setSchema function to know how to serialize/deserialize the tuples, and has getSchema function to return out the stored schema. In other words, SinkStorage stores both the tuples AND schema.

VirtualDocument is an abstraction layer for all the storage-related apis. It currently has MongoDocument[T]. MemoryDocument[T], FileDocument[T] implemented. These implementations are designed to store the actual data(a sequence of T objects), and T's serializer/deserializer if any. Compared to storing tuples like SinkStorage, implementations will ONLY store tuples, NO schema, because schema is very specialized for TupleLike object and should not be part of the Document.

2. Changes in the OpResultStorage

OpResultStorage manages all the opened SinkStorageReader. So to persist this part, the OpResultStorage extends from ConcurrentHashMap[OperatorIdentity, SinkStorageReader] to ConcurrentHashMap[OperatorIdentity, (VirtualDocument[Tuple], Option[Schema])]. This extension is due to the fact that VirtualDocument[T] doesn't have interfaces to acquire the Schema. Option is used because in some cases the schema is not generated yet when the VirtualDocument is initialized

3. New method setSerde in the MongoDocument

A new function is added:

  /**
    * set the serializer & deserializer.
    *
    * @param toDocument: the serializer, convert T to MongoDB's Document.
    * @param fromDocument: the deserializer, convert MongoDB's Document to T.
    */
  def setSerde(toDocument: T => Document, fromDocument: Document => T): Unit = {
    this.toDocument = Some(toDocument)
    this.fromDocument = Some(fromDocument)
  }

this is used to reset the document's the serializer/deserializer . This is needed because in some cases, the document needs to be created, but the serializer and deserializer are not ready yet.

4. New trait, TupleResultStatistics, is added

Since when MongoDB is used for result storage, the statistics of columns will be shown in the result panel. A new trait is added:

package edu.uci.ics.amber.engine.common.storage

trait TupleResultStatistics {
  // a map from numerical fields to stats
  def getNumericColStats: Map[String, Map[String, Any]]

  // a map from date fields to stats
  def getDateColStats: Map[String, Map[String, Any]]

  // a map from categorical fields to stats
  def getCategoricalStats: Map[String, Map[String, Any]]
}

And MongoDocument implements this trait:

  override def getNumericColStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateNumericStats()

  override def getDateColStats: Map[String, Map[String, Any]] = collectionMgr.calculateDateStats()

  override def getCategoricalStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateCategoricalStats()

@bobbai00 bobbai00 self-assigned this Nov 9, 2024

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comments.

@bobbai00
bobbai00 force-pushed the jiadong-unify-storage-api branch from 97dd92c to 04368f4 Compare November 14, 2024 01:42
@bobbai00
bobbai00 force-pushed the jiadong-unify-storage-api branch 2 times, most recently from 7c05491 to 764e1b0 Compare November 29, 2024 04:54
@bobbai00
bobbai00 force-pushed the jiadong-unify-storage-api branch from 764e1b0 to bee72bf Compare December 6, 2024 06:11

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am mainly against of setting the storage schema during propagation function. you could do it in the compiler, add a stage after propagate schemas, to assign schema to corresponding storages.

@bobbai00
bobbai00 force-pushed the jiadong-unify-storage-api branch from 5d06eec to d446cda Compare December 8, 2024 22:51
@bobbai00
bobbai00 requested a review from Yicong-Huang December 8, 2024 22:54

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! please fix the tests

@bobbai00
bobbai00 force-pushed the jiadong-unify-storage-api branch from 2ffa93c to bbc0ecd Compare December 9, 2024 18:21
@bobbai00
bobbai00 merged commit 9fc1d00 into master Dec 9, 2024
@bobbai00
bobbai00 deleted the jiadong-unify-storage-api branch December 9, 2024 18:35
Yicong-Huang pushed a commit that referenced this pull request Dec 16, 2024
…Tuple] (#3024)

This PR removes the `SinkStorageReader` and `SinkStorageWriter`, and
substitute it with `VirtualDocument[Tuple]`

### 1. Recap on `SinkStorage` and `VirtualDocument`

`SinkStorage` is one kinds of storage specialized for Tuple storage. It
relies on the `setSchema` function to know how to serialize/deserialize
the tuples, and has `getSchema` function to return out the stored
schema. In other words, `SinkStorage` stores both the tuples AND schema.

`VirtualDocument` is an abstraction layer for all the storage-related
apis. It currently has `MongoDocument[T]`. `MemoryDocument[T]`,
`FileDocument[T]` implemented. These implementations are designed to
store the actual data(a sequence of `T` objects), and `T`'s
serializer/deserializer if any. Compared to storing tuples like
`SinkStorage`, implementations will ONLY store tuples, NO schema,
because schema is very specialized for `TupleLike` object and should not
be part of the Document.

### 2. Changes in the `OpResultStorage`

`OpResultStorage` manages all the opened `SinkStorageReader`. So to
persist this part, the `OpResultStorage` extends from
`ConcurrentHashMap[OperatorIdentity, SinkStorageReader]` to
`ConcurrentHashMap[OperatorIdentity, (VirtualDocument[Tuple],
Option[Schema])]`. This extension is due to the fact that
`VirtualDocument[T]` doesn't have interfaces to acquire the `Schema`.
`Option` is used because in some cases the schema is not generated yet
when the `VirtualDocument` is initialized

### 3. New method `setSerde` in the `MongoDocument`

A new function is added:

```
  /**
    * set the serializer & deserializer.
    *
    * @PARAM toDocument: the serializer, convert T to MongoDB's Document.
    * @PARAM fromDocument: the deserializer, convert MongoDB's Document to T.
    */
  def setSerde(toDocument: T => Document, fromDocument: Document => T): Unit = {
    this.toDocument = Some(toDocument)
    this.fromDocument = Some(fromDocument)
  }
```

this is used to reset the document's the serializer/deserializer . This
is needed because in some cases, the document needs to be created, but
the serializer and deserializer are not ready yet.

### 4. New trait, `TupleResultStatistics`, is added

Since when MongoDB is used for result storage, the statistics of columns
will be shown in the result panel. A new trait is added:

```
package edu.uci.ics.amber.engine.common.storage

trait TupleResultStatistics {
  // a map from numerical fields to stats
  def getNumericColStats: Map[String, Map[String, Any]]

  // a map from date fields to stats
  def getDateColStats: Map[String, Map[String, Any]]

  // a map from categorical fields to stats
  def getCategoricalStats: Map[String, Map[String, Any]]
}
```

And MongoDocument implements this trait:
```
  override def getNumericColStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateNumericStats()

  override def getDateColStats: Map[String, Map[String, Any]] = collectionMgr.calculateDateStats()

  override def getCategoricalStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateCategoricalStats()
```
Yicong-Huang pushed a commit that referenced this pull request Dec 16, 2024
…Tuple] (#3024)

This PR removes the `SinkStorageReader` and `SinkStorageWriter`, and
substitute it with `VirtualDocument[Tuple]`

### 1. Recap on `SinkStorage` and `VirtualDocument`

`SinkStorage` is one kinds of storage specialized for Tuple storage. It
relies on the `setSchema` function to know how to serialize/deserialize
the tuples, and has `getSchema` function to return out the stored
schema. In other words, `SinkStorage` stores both the tuples AND schema.

`VirtualDocument` is an abstraction layer for all the storage-related
apis. It currently has `MongoDocument[T]`. `MemoryDocument[T]`,
`FileDocument[T]` implemented. These implementations are designed to
store the actual data(a sequence of `T` objects), and `T`'s
serializer/deserializer if any. Compared to storing tuples like
`SinkStorage`, implementations will ONLY store tuples, NO schema,
because schema is very specialized for `TupleLike` object and should not
be part of the Document.

### 2. Changes in the `OpResultStorage`

`OpResultStorage` manages all the opened `SinkStorageReader`. So to
persist this part, the `OpResultStorage` extends from
`ConcurrentHashMap[OperatorIdentity, SinkStorageReader]` to
`ConcurrentHashMap[OperatorIdentity, (VirtualDocument[Tuple],
Option[Schema])]`. This extension is due to the fact that
`VirtualDocument[T]` doesn't have interfaces to acquire the `Schema`.
`Option` is used because in some cases the schema is not generated yet
when the `VirtualDocument` is initialized

### 3. New method `setSerde` in the `MongoDocument`

A new function is added:

```
  /**
    * set the serializer & deserializer.
    *
    * @PARAM toDocument: the serializer, convert T to MongoDB's Document.
    * @PARAM fromDocument: the deserializer, convert MongoDB's Document to T.
    */
  def setSerde(toDocument: T => Document, fromDocument: Document => T): Unit = {
    this.toDocument = Some(toDocument)
    this.fromDocument = Some(fromDocument)
  }
```

this is used to reset the document's the serializer/deserializer . This
is needed because in some cases, the document needs to be created, but
the serializer and deserializer are not ready yet.

### 4. New trait, `TupleResultStatistics`, is added

Since when MongoDB is used for result storage, the statistics of columns
will be shown in the result panel. A new trait is added:

```
package edu.uci.ics.amber.engine.common.storage

trait TupleResultStatistics {
  // a map from numerical fields to stats
  def getNumericColStats: Map[String, Map[String, Any]]

  // a map from date fields to stats
  def getDateColStats: Map[String, Map[String, Any]]

  // a map from categorical fields to stats
  def getCategoricalStats: Map[String, Map[String, Any]]
}
```

And MongoDocument implements this trait:
```
  override def getNumericColStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateNumericStats()

  override def getDateColStats: Map[String, Map[String, Any]] = collectionMgr.calculateDateStats()

  override def getCategoricalStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateCategoricalStats()
```
Yicong-Huang pushed a commit that referenced this pull request Dec 30, 2024
…Tuple] (#3024)

This PR removes the `SinkStorageReader` and `SinkStorageWriter`, and
substitute it with `VirtualDocument[Tuple]`

### 1. Recap on `SinkStorage` and `VirtualDocument`

`SinkStorage` is one kinds of storage specialized for Tuple storage. It
relies on the `setSchema` function to know how to serialize/deserialize
the tuples, and has `getSchema` function to return out the stored
schema. In other words, `SinkStorage` stores both the tuples AND schema.

`VirtualDocument` is an abstraction layer for all the storage-related
apis. It currently has `MongoDocument[T]`. `MemoryDocument[T]`,
`FileDocument[T]` implemented. These implementations are designed to
store the actual data(a sequence of `T` objects), and `T`'s
serializer/deserializer if any. Compared to storing tuples like
`SinkStorage`, implementations will ONLY store tuples, NO schema,
because schema is very specialized for `TupleLike` object and should not
be part of the Document.

### 2. Changes in the `OpResultStorage`

`OpResultStorage` manages all the opened `SinkStorageReader`. So to
persist this part, the `OpResultStorage` extends from
`ConcurrentHashMap[OperatorIdentity, SinkStorageReader]` to
`ConcurrentHashMap[OperatorIdentity, (VirtualDocument[Tuple],
Option[Schema])]`. This extension is due to the fact that
`VirtualDocument[T]` doesn't have interfaces to acquire the `Schema`.
`Option` is used because in some cases the schema is not generated yet
when the `VirtualDocument` is initialized

### 3. New method `setSerde` in the `MongoDocument`

A new function is added:

```
  /**
    * set the serializer & deserializer.
    *
    * @PARAM toDocument: the serializer, convert T to MongoDB's Document.
    * @PARAM fromDocument: the deserializer, convert MongoDB's Document to T.
    */
  def setSerde(toDocument: T => Document, fromDocument: Document => T): Unit = {
    this.toDocument = Some(toDocument)
    this.fromDocument = Some(fromDocument)
  }
```

this is used to reset the document's the serializer/deserializer . This
is needed because in some cases, the document needs to be created, but
the serializer and deserializer are not ready yet.

### 4. New trait, `TupleResultStatistics`, is added

Since when MongoDB is used for result storage, the statistics of columns
will be shown in the result panel. A new trait is added:

```
package edu.uci.ics.amber.engine.common.storage

trait TupleResultStatistics {
  // a map from numerical fields to stats
  def getNumericColStats: Map[String, Map[String, Any]]

  // a map from date fields to stats
  def getDateColStats: Map[String, Map[String, Any]]

  // a map from categorical fields to stats
  def getCategoricalStats: Map[String, Map[String, Any]]
}
```

And MongoDocument implements this trait:
```
  override def getNumericColStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateNumericStats()

  override def getDateColStats: Map[String, Map[String, Any]] = collectionMgr.calculateDateStats()

  override def getCategoricalStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateCategoricalStats()
```
Yicong-Huang pushed a commit that referenced this pull request Dec 30, 2024
…Tuple] (#3024)

This PR removes the `SinkStorageReader` and `SinkStorageWriter`, and
substitute it with `VirtualDocument[Tuple]`

### 1. Recap on `SinkStorage` and `VirtualDocument`

`SinkStorage` is one kinds of storage specialized for Tuple storage. It
relies on the `setSchema` function to know how to serialize/deserialize
the tuples, and has `getSchema` function to return out the stored
schema. In other words, `SinkStorage` stores both the tuples AND schema.

`VirtualDocument` is an abstraction layer for all the storage-related
apis. It currently has `MongoDocument[T]`. `MemoryDocument[T]`,
`FileDocument[T]` implemented. These implementations are designed to
store the actual data(a sequence of `T` objects), and `T`'s
serializer/deserializer if any. Compared to storing tuples like
`SinkStorage`, implementations will ONLY store tuples, NO schema,
because schema is very specialized for `TupleLike` object and should not
be part of the Document.

### 2. Changes in the `OpResultStorage`

`OpResultStorage` manages all the opened `SinkStorageReader`. So to
persist this part, the `OpResultStorage` extends from
`ConcurrentHashMap[OperatorIdentity, SinkStorageReader]` to
`ConcurrentHashMap[OperatorIdentity, (VirtualDocument[Tuple],
Option[Schema])]`. This extension is due to the fact that
`VirtualDocument[T]` doesn't have interfaces to acquire the `Schema`.
`Option` is used because in some cases the schema is not generated yet
when the `VirtualDocument` is initialized

### 3. New method `setSerde` in the `MongoDocument`

A new function is added:

```
  /**
    * set the serializer & deserializer.
    *
    * @PARAM toDocument: the serializer, convert T to MongoDB's Document.
    * @PARAM fromDocument: the deserializer, convert MongoDB's Document to T.
    */
  def setSerde(toDocument: T => Document, fromDocument: Document => T): Unit = {
    this.toDocument = Some(toDocument)
    this.fromDocument = Some(fromDocument)
  }
```

this is used to reset the document's the serializer/deserializer . This
is needed because in some cases, the document needs to be created, but
the serializer and deserializer are not ready yet.

### 4. New trait, `TupleResultStatistics`, is added

Since when MongoDB is used for result storage, the statistics of columns
will be shown in the result panel. A new trait is added:

```
package edu.uci.ics.amber.engine.common.storage

trait TupleResultStatistics {
  // a map from numerical fields to stats
  def getNumericColStats: Map[String, Map[String, Any]]

  // a map from date fields to stats
  def getDateColStats: Map[String, Map[String, Any]]

  // a map from categorical fields to stats
  def getCategoricalStats: Map[String, Map[String, Any]]
}
```

And MongoDocument implements this trait:
```
  override def getNumericColStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateNumericStats()

  override def getDateColStats: Map[String, Map[String, Any]] = collectionMgr.calculateDateStats()

  override def getCategoricalStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateCategoricalStats()
```
SarahAsad23 pushed a commit to madisonmlin/texera that referenced this pull request May 20, 2026
…Tuple] (apache#3024)

This PR removes the `SinkStorageReader` and `SinkStorageWriter`, and
substitute it with `VirtualDocument[Tuple]`

### 1. Recap on `SinkStorage` and `VirtualDocument`

`SinkStorage` is one kinds of storage specialized for Tuple storage. It
relies on the `setSchema` function to know how to serialize/deserialize
the tuples, and has `getSchema` function to return out the stored
schema. In other words, `SinkStorage` stores both the tuples AND schema.

`VirtualDocument` is an abstraction layer for all the storage-related
apis. It currently has `MongoDocument[T]`. `MemoryDocument[T]`,
`FileDocument[T]` implemented. These implementations are designed to
store the actual data(a sequence of `T` objects), and `T`'s
serializer/deserializer if any. Compared to storing tuples like
`SinkStorage`, implementations will ONLY store tuples, NO schema,
because schema is very specialized for `TupleLike` object and should not
be part of the Document.

### 2. Changes in the `OpResultStorage`

`OpResultStorage` manages all the opened `SinkStorageReader`. So to
persist this part, the `OpResultStorage` extends from
`ConcurrentHashMap[OperatorIdentity, SinkStorageReader]` to
`ConcurrentHashMap[OperatorIdentity, (VirtualDocument[Tuple],
Option[Schema])]`. This extension is due to the fact that
`VirtualDocument[T]` doesn't have interfaces to acquire the `Schema`.
`Option` is used because in some cases the schema is not generated yet
when the `VirtualDocument` is initialized

### 3. New method `setSerde` in the `MongoDocument`

A new function is added:

```
  /**
    * set the serializer & deserializer.
    *
    * @PARAM toDocument: the serializer, convert T to MongoDB's Document.
    * @PARAM fromDocument: the deserializer, convert MongoDB's Document to T.
    */
  def setSerde(toDocument: T => Document, fromDocument: Document => T): Unit = {
    this.toDocument = Some(toDocument)
    this.fromDocument = Some(fromDocument)
  }
```

this is used to reset the document's the serializer/deserializer . This
is needed because in some cases, the document needs to be created, but
the serializer and deserializer are not ready yet.

### 4. New trait, `TupleResultStatistics`, is added

Since when MongoDB is used for result storage, the statistics of columns
will be shown in the result panel. A new trait is added:

```
package edu.uci.ics.amber.engine.common.storage

trait TupleResultStatistics {
  // a map from numerical fields to stats
  def getNumericColStats: Map[String, Map[String, Any]]

  // a map from date fields to stats
  def getDateColStats: Map[String, Map[String, Any]]

  // a map from categorical fields to stats
  def getCategoricalStats: Map[String, Map[String, Any]]
}
```

And MongoDocument implements this trait:
```
  override def getNumericColStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateNumericStats()

  override def getDateColStats: Map[String, Map[String, Any]] = collectionMgr.calculateDateStats()

  override def getCategoricalStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateCategoricalStats()
```
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…Tuple] (apache#3024)

This PR removes the `SinkStorageReader` and `SinkStorageWriter`, and
substitute it with `VirtualDocument[Tuple]`

### 1. Recap on `SinkStorage` and `VirtualDocument`

`SinkStorage` is one kinds of storage specialized for Tuple storage. It
relies on the `setSchema` function to know how to serialize/deserialize
the tuples, and has `getSchema` function to return out the stored
schema. In other words, `SinkStorage` stores both the tuples AND schema.

`VirtualDocument` is an abstraction layer for all the storage-related
apis. It currently has `MongoDocument[T]`. `MemoryDocument[T]`,
`FileDocument[T]` implemented. These implementations are designed to
store the actual data(a sequence of `T` objects), and `T`'s
serializer/deserializer if any. Compared to storing tuples like
`SinkStorage`, implementations will ONLY store tuples, NO schema,
because schema is very specialized for `TupleLike` object and should not
be part of the Document.

### 2. Changes in the `OpResultStorage`

`OpResultStorage` manages all the opened `SinkStorageReader`. So to
persist this part, the `OpResultStorage` extends from
`ConcurrentHashMap[OperatorIdentity, SinkStorageReader]` to
`ConcurrentHashMap[OperatorIdentity, (VirtualDocument[Tuple],
Option[Schema])]`. This extension is due to the fact that
`VirtualDocument[T]` doesn't have interfaces to acquire the `Schema`.
`Option` is used because in some cases the schema is not generated yet
when the `VirtualDocument` is initialized

### 3. New method `setSerde` in the `MongoDocument`

A new function is added:

```
  /**
    * set the serializer & deserializer.
    *
    * @PARAM toDocument: the serializer, convert T to MongoDB's Document.
    * @PARAM fromDocument: the deserializer, convert MongoDB's Document to T.
    */
  def setSerde(toDocument: T => Document, fromDocument: Document => T): Unit = {
    this.toDocument = Some(toDocument)
    this.fromDocument = Some(fromDocument)
  }
```

this is used to reset the document's the serializer/deserializer . This
is needed because in some cases, the document needs to be created, but
the serializer and deserializer are not ready yet.

### 4. New trait, `TupleResultStatistics`, is added

Since when MongoDB is used for result storage, the statistics of columns
will be shown in the result panel. A new trait is added:

```
package edu.uci.ics.amber.engine.common.storage

trait TupleResultStatistics {
  // a map from numerical fields to stats
  def getNumericColStats: Map[String, Map[String, Any]]

  // a map from date fields to stats
  def getDateColStats: Map[String, Map[String, Any]]

  // a map from categorical fields to stats
  def getCategoricalStats: Map[String, Map[String, Any]]
}
```

And MongoDocument implements this trait:
```
  override def getNumericColStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateNumericStats()

  override def getDateColStats: Map[String, Map[String, Any]] = collectionMgr.calculateDateStats()

  override def getCategoricalStats: Map[String, Map[String, Any]] =
    collectionMgr.calculateCategoricalStats()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants