Skip to content

Commit 8691ece

Browse files
committed
Bump iglu-scala-client to 4.0.0
1 parent cd79f64 commit 8691ece

File tree

3 files changed

+36
-61
lines changed

3 files changed

+36
-61
lines changed

Diff for: modules/common/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/common/SchemaProvider.scala

+17-24
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
package com.snowplowanalytics.snowplow.rdbloader.common
1212

1313
import cats.{Monad, Order}
14-
import cats.data.EitherT
14+
import cats.data.{EitherT, NonEmptyList}
1515
import cats.effect.Clock
16-
import cats.syntax.all._
16+
import io.circe.Json
1717
import com.snowplowanalytics.iglu.client.resolver.registries.RegistryLookup
1818
import com.snowplowanalytics.iglu.client.{ClientError, Resolver}
19-
import com.snowplowanalytics.iglu.core.{SchemaCriterion, SchemaKey}
19+
import com.snowplowanalytics.iglu.core.{SchemaKey, SelfDescribingSchema}
2020
import com.snowplowanalytics.iglu.schemaddl.jsonschema.Schema
2121
import com.snowplowanalytics.iglu.schemaddl.jsonschema.circe.implicits.toSchema
2222
import com.snowplowanalytics.snowplow.badrows.FailureDetails.LoaderIgluError
@@ -40,32 +40,25 @@ object SchemaProvider {
4040
schema <- EitherT.fromOption[F](Schema.parse(json), parseSchemaBadRow(schemaKey))
4141
} yield schema
4242

43+
def parseSchemaJsons[F[_]](jsons: NonEmptyList[SelfDescribingSchema[Json]]): Either[LoaderIgluError, NonEmptyList[SchemaWithKey]] =
44+
jsons.traverse { json =>
45+
Schema
46+
.parse(json.schema)
47+
.toRight(parseSchemaBadRow(json.self.schemaKey))
48+
.map(schema => SchemaWithKey(json.self.schemaKey, schema))
49+
}
50+
4351
def fetchSchemasWithSameModel[F[_]: Clock: Monad: RegistryLookup](
4452
resolver: Resolver[F],
4553
schemaKey: SchemaKey
4654
): EitherT[F, LoaderIgluError, List[SchemaWithKey]] =
47-
EitherT(resolver.listSchemasLike(schemaKey))
48-
.leftMap(resolverFetchBadRow(schemaKey.vendor, schemaKey.name, schemaKey.format, schemaKey.version.model))
49-
.map(_.schemas)
50-
.flatMap(schemaKeys =>
51-
schemaKeys
52-
.traverse(schemaKey =>
53-
getSchema(resolver, schemaKey)
54-
.map(schema => SchemaWithKey(schemaKey, schema))
55-
)
56-
)
57-
58-
private def resolverFetchBadRow(
59-
vendor: String,
60-
name: String,
61-
format: String,
62-
model: Int
63-
)(
64-
e: ClientError.ResolutionError
65-
): LoaderIgluError =
66-
LoaderIgluError.SchemaListNotFound(SchemaCriterion(vendor = vendor, name = name, format = format, model = model), e)
55+
for {
56+
jsons <- EitherT(resolver.lookupSchemasUntil(schemaKey))
57+
.leftMap(e => resolverBadRow(e.schemaKey)(e.error))
58+
schemas <- EitherT.fromEither[F](parseSchemaJsons(jsons))
59+
} yield schemas.toList
6760

68-
private def resolverBadRow(schemaKey: SchemaKey)(e: ClientError.ResolutionError): LoaderIgluError =
61+
def resolverBadRow(schemaKey: SchemaKey)(e: ClientError.ResolutionError): LoaderIgluError =
6962
LoaderIgluError.IgluError(schemaKey, e)
7063

7164
private def parseSchemaBadRow(schemaKey: SchemaKey): LoaderIgluError =

Diff for: modules/common/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/common/transformation/Transformed.scala

+18-36
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@ import cats.implicits._
1515
import cats.data.{EitherT, NonEmptyList}
1616
import cats.effect.Clock
1717
import com.snowplowanalytics.iglu.client.Resolver
18+
import com.snowplowanalytics.iglu.client.resolver.SchemaContentList
1819
import com.snowplowanalytics.iglu.client.resolver.registries.RegistryLookup
19-
import com.snowplowanalytics.iglu.client.resolver.Resolver.{ResolverResult, SchemaListKey}
20-
import com.snowplowanalytics.iglu.core.{SchemaCriterion, SchemaKey, SchemaList, SchemaMap, SelfDescribingSchema}
20+
import com.snowplowanalytics.iglu.client.resolver.Resolver.ResolverResult
21+
import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaMap, SelfDescribingSchema}
2122
import com.snowplowanalytics.iglu.schemaddl.jsonschema.Schema
2223
import com.snowplowanalytics.iglu.schemaddl.parquet.{Field, FieldValue}
2324
import com.snowplowanalytics.iglu.schemaddl.redshift._
2425
import com.snowplowanalytics.snowplow.analytics.scalasdk.Event
2526
import com.snowplowanalytics.snowplow.badrows.{BadRow, FailureDetails, Processor}
2627
import com.snowplowanalytics.snowplow.badrows.FailureDetails.LoaderIgluError
27-
import com.snowplowanalytics.snowplow.badrows.FailureDetails.LoaderIgluError.SchemaListNotFound
2828
import com.snowplowanalytics.snowplow.rdbloader.common.Common.AtomicSchema
2929
import com.snowplowanalytics.snowplow.rdbloader.common.LoaderMessage.TypesInfo.Shredded.ShreddedFormat
3030
import com.snowplowanalytics.snowplow.rdbloader.common.SchemaProvider
31-
import com.snowplowanalytics.snowplow.rdbloader.common.SchemaProvider.SchemaWithKey
3231

3332
/** Represents transformed data in blob storage */
3433

@@ -151,25 +150,13 @@ object Transformed {
151150

152151
def getShredModel[F[_]: Monad: Clock: RegistryLookup](
153152
schemaKey: SchemaKey,
154-
schemaKeys: List[SchemaKey],
155-
resolver: Resolver[F]
153+
schemaContentList: SchemaContentList
156154
): EitherT[F, LoaderIgluError, ShredModel] =
157-
schemaKeys
158-
.traverse { sk =>
159-
SchemaProvider
160-
.getSchema(resolver, sk)
161-
.map(schema => SchemaWithKey(sk, schema))
162-
}
163-
.flatMap { schemaWithKeyList =>
164-
EitherT
165-
.fromOption[F][FailureDetails.LoaderIgluError, NonEmptyList[SchemaWithKey]](
166-
NonEmptyList.fromList(schemaWithKeyList),
167-
FailureDetails.LoaderIgluError.InvalidSchema(schemaKey, s"Empty resolver response for $schemaKey")
168-
)
169-
.map { nel =>
170-
val schemas = nel.map(swk => SelfDescribingSchema[Schema](SchemaMap(swk.schemaKey), swk.schema))
171-
foldMapRedshiftSchemas(schemas)(schemaKey)
172-
}
155+
EitherT
156+
.fromEither[F](SchemaProvider.parseSchemaJsons(schemaContentList))
157+
.map { nel =>
158+
val schemas = nel.map(swk => SelfDescribingSchema[Schema](SchemaMap(swk.schemaKey), swk.schema))
159+
foldMapRedshiftSchemas(schemas)(schemaKey)
173160
}
174161

175162
/**
@@ -179,32 +166,27 @@ object Transformed {
179166
schemaKey: SchemaKey,
180167
shredModelCache: ShredModelCache[F],
181168
resolver: => Resolver[F]
182-
): EitherT[F, LoaderIgluError, ShredModel] = {
183-
val criterion = SchemaCriterion(schemaKey.vendor, schemaKey.name, schemaKey.format, Some(schemaKey.version.model), None, None)
184-
185-
EitherT(resolver.listSchemasResult(schemaKey.vendor, schemaKey.name, schemaKey.version.model, Some(schemaKey)))
186-
.leftMap(error => SchemaListNotFound(criterion, error))
169+
): EitherT[F, LoaderIgluError, ShredModel] =
170+
EitherT(resolver.lookupSchemasUntilResult(schemaKey))
171+
.leftMap(e => SchemaProvider.resolverBadRow(e.schemaKey)(e.error))
187172
.flatMap {
188-
case cached: ResolverResult.Cached[SchemaListKey, SchemaList] =>
189-
lookupInCache(schemaKey, resolver, shredModelCache, cached)
190-
case ResolverResult.NotCached(schemaList) =>
191-
val schemaKeys = schemaList.schemas
192-
getShredModel(schemaKey, schemaKeys, resolver)
173+
case cached: ResolverResult.Cached[SchemaKey, SchemaContentList] =>
174+
lookupInCache(schemaKey, shredModelCache, cached)
175+
case ResolverResult.NotCached(schemaContentList) =>
176+
getShredModel(schemaKey, schemaContentList)
193177
}
194-
}
195178

196179
def lookupInCache[F[_]: Monad: Clock: RegistryLookup](
197180
schemaKey: SchemaKey,
198-
resolver: Resolver[F],
199181
shredModelCache: ShredModelCache[F],
200-
cached: ResolverResult.Cached[SchemaListKey, SchemaList]
182+
cached: ResolverResult.Cached[SchemaKey, SchemaContentList]
201183
) = {
202184
val key = (schemaKey, cached.timestamp)
203185
EitherT.liftF(shredModelCache.get(key)).flatMap {
204186
case Some(model) =>
205187
EitherT.pure[F, FailureDetails.LoaderIgluError](model)
206188
case None =>
207-
getShredModel(schemaKey, cached.value.schemas, resolver)
189+
getShredModel[F](schemaKey, cached.value)
208190
.semiflatTap(props => shredModelCache.put(key, props))
209191
}
210192
}

Diff for: project/Dependencies.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Dependencies {
1515
object V {
1616
// Scala (Loader)
1717
val decline = "2.4.1"
18-
val igluClient = "3.1.1"
18+
val igluClient = "4.0.0-M2"
1919
val igluCore = "1.1.1"
2020
val badrows = "2.2.0"
2121
val analyticsSdk = "3.1.0"

0 commit comments

Comments
 (0)