Skip to content

Commit

Permalink
Deploying to gh-pages from @ 13a717c 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizalo committed Feb 2, 2024
1 parent 0484f87 commit 99a5bc7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions docs/exclusive.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ val sparkCol = f.expr("array_sort(value, (l, r) -> case " +

val doricCol = colArray[Row]("value").sortBy(CName("name"), CNameOrd("age", Desc))
// doricCol: ArrayColumn[Row] = TransformationDoricColumn(
// Kleisli(scala.Function1$$Lambda$2999/0x000000080133f040@3d5f6088)
// Kleisli(scala.Function1$$Lambda$3002/0x0000000801346040@3ea4712b)
// )

dfArrayStruct.select(sparkCol.as("sorted")).show(false)
Expand Down Expand Up @@ -151,7 +151,7 @@ val mapColDoric = colString("value").matches[String]
.caseW(_.length > 4, "error key".lit)
.otherwiseNull
// mapColDoric: DoricColumn[String] = TransformationDoricColumn(
// Kleisli(scala.Function1$$Lambda$2999/0x000000080133f040@1a5d0d94)
// Kleisli(scala.Function1$$Lambda$3002/0x0000000801346040@569b57c4)
// )

dfMatch.withColumn("mapResult", mapColDoric).show()
Expand Down
30 changes: 15 additions & 15 deletions docs/implicits.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ val complexS: Column =
f.transform(f.col("arr"), x => x + 1),
f.lit(0),
(x, y) => x + y)
// complexS: Column = aggregate(transform(arr, lambdafunction((x_0 + 1), x_0)), 0, lambdafunction((x_1 + y_2), x_1, y_2), lambdafunction(x_3, x_3))
// complexS: Column = aggregate(transform(arr, lambdafunction((x_0 + 1), x_0)), 0, lambdafunction((x_1 + y_2), x_1, y_2), lambdafunction(x_3, x_3))

dfArrays.select(complexS as "complexTransformation").show()
// +---------------------+
Expand All @@ -85,8 +85,8 @@ val complexCol: DoricColumn[Int] =
.transform(_ + 1.lit)
.aggregate(0.lit)(_ + _)
// complexCol: DoricColumn[Int] = TransformationDoricColumn(
// Kleisli(scala.Function1$$Lambda$2999/0x000000080133f040@39459b5a)
// )
// Kleisli(scala.Function1$$Lambda$3002/0x0000000801346040@7ec594eb)
// )

dfArrays.select(complexCol as "complexTransformation").show()
// +---------------------+
Expand Down Expand Up @@ -143,7 +143,7 @@ Still, doric will allow you to perform that operation provided that you explicit

```scala
val df1 = spark.range(1,10).toDF().withColumn("x", concat(colLong("id").cast[String], "jander".lit))
// df1: org.apache.spark.sql.package.DataFrame = [id: bigint, x: string]
// df1: org.apache.spark.sql.package.DataFrame = [id: bigint, x: string]
df1.show()
// +---+-------+
// | id| x|
Expand All @@ -165,7 +165,7 @@ Let's also consider the following example:

```scala
val dfEq = List((1, "1"), (1, " 1"), (1, " 1 ")).toDF("int", "str")
// dfEq: org.apache.spark.sql.package.DataFrame = [int: int, str: string]
// dfEq: org.apache.spark.sql.package.DataFrame = [int: int, str: string]
dfEq.withColumn("eq", f.col("int") === f.col("str"))
// res5: org.apache.spark.sql.package.DataFrame = [int: int, str: string ... 1 more field]
```
Expand Down Expand Up @@ -238,7 +238,7 @@ Last, note that we can also emulate the default Spark behaviour, enabling implic
with an explicit import statement:

```scala
import doric.implicitConversions.implicitSafeCast
import doric.implicitConversions.implicitSafeCast

dfEq.withColumn("eq", colString("str") === colInt("int") ).show()
// +---+---+-----+
Expand All @@ -257,9 +257,9 @@ Sometimes, Spark allows us to insert literal values to simplify our code:

```scala
val intDF = List(1,2,3).toDF("int")
// intDF: org.apache.spark.sql.package.DataFrame = [int: int]
// intDF: org.apache.spark.sql.package.DataFrame = [int: int]
val colS = f.col("int") + 1
// colS: Column = (int + 1)
// colS: Column = (int + 1)

intDF.select(colS).show()
// +---------+
Expand All @@ -277,8 +277,8 @@ The default doric syntax is a little stricter and forces us to transform these v
```scala
val colD = colInt("int") + 1.lit
// colD: DoricColumn[Int] = TransformationDoricColumn(
// Kleisli(scala.Function1$$Lambda$2999/0x000000080133f040@18f28a93)
// )
// Kleisli(scala.Function1$$Lambda$3002/0x0000000801346040@21dcd0b5)
// )

intDF.select(colD).show()
// +---------+
Expand All @@ -295,15 +295,15 @@ However, we can also profit from the same literal syntax with the help of implic
we have to _explicitly_ add the following import statement:

```scala
import doric.implicitConversions.literalConversion
import doric.implicitConversions.literalConversion
val colSugarD = colInt("int") + 1
// colSugarD: DoricColumn[Int] = TransformationDoricColumn(
// Kleisli(scala.Function1$$Lambda$2999/0x000000080133f040@5152538d)
// )
// Kleisli(scala.Function1$$Lambda$3002/0x0000000801346040@ff8fe1f)
// )
val columConcatLiterals = concat("this", "is","doric") // concat expects DoricColumn[String] values, the conversion puts them as expected
// columConcatLiterals: StringColumn = TransformationDoricColumn(
// Kleisli(scala.Function1$$Lambda$2999/0x000000080133f040@793ac211)
// ) // concat expects DoricColumn[String] values, the conversion puts them as expected
// Kleisli(scala.Function1$$Lambda$3002/0x0000000801346040@730fcd33)
// )

intDF.select(colSugarD, columConcatLiterals).show()
// +---------+-----------------------+
Expand Down
15 changes: 8 additions & 7 deletions docs/modularity.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ userDF.show()
// | Bar| New York| 40|
// | John| Paris| 30|
// +---------+---------+--------+
//
//
userDF.printSchema()
// root
// |-- name_user: string (nullable = true)
Expand All @@ -32,11 +32,12 @@ We may refer to these columns using their full names:

```scala
f.col("name_user")
// res2: Column = name_user
// res2: Column = name_user
f.col("age_user")
// res3: Column = age_user
// res3: Column = age_user
f.col("city_user")
// res4: Column = city_user
//and many more
```

But we may also want to create a _reusable_ function which abstract away the common suffix and allows us to focus
Expand Down Expand Up @@ -77,7 +78,7 @@ Doric includes in the exception the exact line of the malformed column reference
and this will be of great help in solving our problem. However, the following doric function doesn't really work:

```scala
import doric.types.SparkType
import doric.types.SparkType
def user[T: SparkType](colName: String): DoricColumn[T] = {
col[T](colName + "_user")
}
Expand Down Expand Up @@ -109,9 +110,9 @@ function:


```scala
import doric._
import doric.sem.Location
import doric.types.SparkType
import doric._
import doric.sem.Location
import doric.types.SparkType

def user[T: SparkType](colName: String)(implicit location: Location): DoricColumn[T] = {
col[T](colName + "_user")
Expand Down
8 changes: 4 additions & 4 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _Maven_
Doric is committed to use the most modern APIs first.
<!-- * Doric is compatible with Spark version 3.4.0. -->
* The latest stable version of doric is 0.0.7.
* The latest experimental version of doric is 0.0.0+1-3666b77a-SNAPSHOT.
* The latest experimental version of doric is 0.0.0+1-13a717c2-SNAPSHOT.
* Doric is compatible with the following Spark versions:

| Spark | Scala | Tested | doric |
Expand Down Expand Up @@ -85,7 +85,7 @@ It's only when we try to construct the DataFrame that an exception is raised at
```scala
df
// org.apache.spark.sql.AnalysisException: [DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES] Cannot resolve "(value * true)" due to data type mismatch: the left and right operands of the binary operator have incompatible types ("INT" and "BOOLEAN").;
// 'Project [unresolvedalias((value#365 * true), Some(org.apache.spark.sql.Column$$Lambda$5125/0x0000000801bc7040@5d0b7c47))]
// 'Project [unresolvedalias((value#365 * true), Some(org.apache.spark.sql.Column$$Lambda$5128/0x0000000801bcd040@112a454))]
// +- LocalRelation [value#365]
//
// at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.dataTypeMismatch(package.scala:73)
Expand Down Expand Up @@ -182,7 +182,7 @@ strDf.select(f.col("str").asDoric[String]).show()
strDf.select((f.col("str") + f.lit(true)).asDoric[String]).show()
// doric.sem.DoricMultiError: Found 1 error in select
// [DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES] Cannot resolve "(str + true)" due to data type mismatch: the left and right operands of the binary operator have incompatible types ("DOUBLE" and "BOOLEAN").;
// 'Project [unresolvedalias((cast(str#378 as double) + true), Some(org.apache.spark.sql.Column$$Lambda$5125/0x0000000801bc7040@5d0b7c47))]
// 'Project [unresolvedalias((cast(str#378 as double) + true), Some(org.apache.spark.sql.Column$$Lambda$5128/0x0000000801bcd040@112a454))]
// +- Project [value#375 AS str#378]
// +- LocalRelation [value#375]
//
Expand All @@ -196,7 +196,7 @@ strDf.select((f.col("str") + f.lit(true)).asDoric[String]).show()
// at repl.MdocSession$MdocApp$$anonfun$2.apply(quickstart.md:76)
// at repl.MdocSession$MdocApp$$anonfun$2.apply(quickstart.md:76)
// Caused by: org.apache.spark.sql.AnalysisException: [DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES] Cannot resolve "(str + true)" due to data type mismatch: the left and right operands of the binary operator have incompatible types ("DOUBLE" and "BOOLEAN").;
// 'Project [unresolvedalias((cast(str#378 as double) + true), Some(org.apache.spark.sql.Column$$Lambda$5125/0x0000000801bc7040@5d0b7c47))]
// 'Project [unresolvedalias((cast(str#378 as double) + true), Some(org.apache.spark.sql.Column$$Lambda$5128/0x0000000801bcd040@112a454))]
// +- Project [value#375 AS str#378]
// +- LocalRelation [value#375]
//
Expand Down
2 changes: 1 addition & 1 deletion docs/validations.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ raising a run-time exception:
// Spark
List(1,2,3).toDF().select(f.col("id")+1)
// org.apache.spark.sql.AnalysisException: [UNRESOLVED_COLUMN.WITH_SUGGESTION] A column or function parameter with name `id` cannot be resolved. Did you mean one of the following? [`value`].;
// 'Project [unresolvedalias(('id + 1), Some(org.apache.spark.sql.Column$$Lambda$5125/0x0000000801bc7040@5d0b7c47))]
// 'Project [unresolvedalias(('id + 1), Some(org.apache.spark.sql.Column$$Lambda$5128/0x0000000801bcd040@112a454))]
// +- LocalRelation [value#399]
//
// at org.apache.spark.sql.errors.QueryCompilationErrors$.unresolvedAttributeError(QueryCompilationErrors.scala:221)
Expand Down

0 comments on commit 99a5bc7

Please sign in to comment.