Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YtOutputWriter should expose WriteTable#config #65

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class YtOutputWriter(richPath: YPathEnriched,
val appendPath = richPath.withAttr("append", "true").toYPath
log.debugLazy(s"Initialize new write: $appendPath, transaction: $transactionGuid")
val request = WriteTable.builder[InternalRow]()
.setConfig(options.getYtConf(TableWriterConfig).orNull)
.setPath(appendPath)
.setSerializationContext(new WriteSerializationContext(new InternalRowSerializer(schema, WriteSchemaConverter(options))))
.setTransactionalOptions(new TransactionalOptions(GUID.valueOf(transactionGuid)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ object YtTableSparkSettings {

case object SortColumns extends ConfigEntry[Seq[String]]("sort_columns", Some(Nil))

case object TableWriterConfig extends ConfigEntry[YTreeNode]("table_writer")

case object UniqueKeys extends ConfigEntry[Boolean]("unique_keys", Some(false))

case object InconsistentDynamicWrite extends ConfigEntry[Boolean]("inconsistent_dynamic_write", Some(false))
Expand Down Expand Up @@ -111,7 +113,7 @@ object YtTableSparkSettings {
}.getOrElse(str)
}

val excludeOptions: Set[String] = Set(SortColumns, Schema, WriteTypeV3, NullTypeAllowed, Path).map(_.name)
val excludeOptions: Set[String] = Set(SortColumns, Schema, WriteTypeV3, NullTypeAllowed, Path, TableWriterConfig).map(_.name)
}

def isTable(configuration: Configuration): Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ class YtOutputWriterTest extends FlatSpec with TmpDir with LocalSpark with Match
YtDataCheck.yPathShouldContainExpectedData(yPath, sampleData)(_.getValues.get(0).longValue())
}

it should "be able to configure table writer" in {
import spark.implicits._
val sampleData = Seq(SampleRow(1, 1.0, "F" * (16 << 20)))

val df = spark.createDataset(sampleData)
df.write.format("yt").option("table_writer", "{max_row_weight=20000000}").save("ytTable:/" + tmpPath)

val yPath = YPath.simple(YtWrapper.formatPath(tmpPath))

YtDataCheck.yPathShouldContainExpectedData(yPath, sampleData)(_.getValues.get(0).longValue())
}

it should "correctly serialize time to YSON" in {
import spark.implicits._
val sampleData = (1 to 1000).map(n => SampleRow2(Nested(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.circe.parser._
import io.circe.syntax._
import org.apache.log4j.Level
import tech.ytsaurus.spyt.wrapper.Utils.parseDuration
import tech.ytsaurus.ysontree.{YTreeNode, YTreeTextSerializer}

import scala.concurrent.duration._

Expand Down Expand Up @@ -55,6 +56,7 @@ object ConfigEntry {
}

implicit val levelAdapter: ValueAdapter[Level] = (value: String) => Level.toLevel(value)
implicit val yTreeNodeAdapter: ValueAdapter[YTreeNode] = (value: String) => YTreeTextSerializer.deserialize(value)
}

def fromJsonTyped[S](value: String)(implicit decoder: Decoder[S]): S = {
Expand Down
Loading