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

Implement geo API in test executor #446

Merged
merged 3 commits into from
Sep 29, 2021
Merged

Implement geo API in test executor #446

merged 3 commits into from
Sep 29, 2021

Conversation

mvelimir
Copy link
Collaborator

Resolves #191

@mvelimir mvelimir requested a review from a team as a code owner September 19, 2021 09:49
Copy link
Member

@mijicd mijicd left a comment

Choose a reason for hiding this comment

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

First pass done. Once you address the comments I'll re-review. It's getting there!

Comment on lines 124 to 125
val key = input.head.asString
val unit = input.last.asString match {
Copy link
Member

Choose a reason for hiding this comment

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

These are unsafe calls.

orWrongType(isSortedSet(key))(
for {
scoreMap <- sortedSets.getOrElse(key, Map.empty)
hashes = members collect scoreMap
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use functions as operators.

Comment on lines 162 to 165
hashOption.map { hash =>
val geoHash = Hash.asGeoHash(hash.toLong)
RespValue.bulkString(geoHash)
}.getOrElse(RespValue.NullBulkString)
Copy link
Member

Choose a reason for hiding this comment

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

Prefer fold to map + getOrElse. Less important, avoid long expressions in yield. You can calculate the array contents before.

Comment on lines 179 to 186
hashes.map { hashOption =>
hashOption.map { hash =>
val longLat = Hash.decodeHash(hash.toLong)
RespValue.array(
RespValue.bulkString(longLat.longitude.toString),
RespValue.bulkString(longLat.latitude.toString)
)
}.getOrElse(RespValue.NullArray)
Copy link
Member

Choose a reason for hiding this comment

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

Same remarks as above.

)

case api.Geo.GeoPos =>
val key = input.head.asString
Copy link
Member

Choose a reason for hiding this comment

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

Unsafe call.

case api.Geo.GeoRadius =>
val stringInput = input.map(_.asString)

val key = stringInput.head
Copy link
Member

Choose a reason for hiding this comment

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

Unsafe call.

Comment on lines 203 to 205
val withCoord = stringInput.find(_ == "WITHCOORD")
val withDist = stringInput.find(_ == "WITHDIST")
val withHash = stringInput.find(_ == "WITHHASH")
Copy link
Member

Choose a reason for hiding this comment

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

WithCoord, WithDist and WithHash have stringify methods. Use it instead of raw values. Technically speaking it's less efficient but it reduces the amount of magic values roaming around the code.

Comment on lines 206 to 219
val count = stringInput.toList.sliding(2) collectFirst { case "COUNT" :: count :: _ =>
count.toInt
}
val order = stringInput collectFirst {
case "ASC" => Order.Ascending
case "DESC" => Order.Descending
}
val store = stringInput.toList.sliding(2) collectFirst { case "STORE" :: key :: _ =>
key
}
val storeDist = stringInput.toList.sliding(2) collectFirst { case "STOREDIST" :: key :: _ =>
key
}

Copy link
Member

Choose a reason for hiding this comment

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

Please don't use functions as operators. Also, take care of the "magic" values.

case api.Geo.GeoRadiusByMember =>
val stringInput = input.map(_.asString)

val key = stringInput.head
Copy link
Member

Choose a reason for hiding this comment

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

Unsafe call.

Comment on lines 292 to 307
val withCoord = stringInput.find(_ == "WITHCOORD")
val withDist = stringInput.find(_ == "WITHDIST")
val withHash = stringInput.find(_ == "WITHHASH")
val count = stringInput.toList.sliding(2) collectFirst { case "COUNT" :: count :: _ =>
count.toInt
}
val order = stringInput collectFirst {
case "ASC" => Order.Ascending
case "DESC" => Order.Descending
}
val store = stringInput.toList.sliding(2) collectFirst { case "STORE" :: key :: _ =>
key
}
val storeDist = stringInput.toList.sliding(2) collectFirst { case "STOREDIST" :: key :: _ =>
key
}
Copy link
Member

Choose a reason for hiding this comment

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

Checkout the remarks given above.

Comment on lines +2417 to +2437
private[this] def orMissingParameter2[A, B](paramA: Option[A], paramB: Option[B])(
program: (A, B) => USTM[RespValue]
): USTM[RespValue] =
apply(apply(Some(program.curried))(paramA))(paramB).getOrElse(STM.succeedNow(Replies.Error))

private[this] def orMissingParameter3[A, B, C](paramA: Option[A], paramB: Option[B], paramC: Option[C])(
program: (A, B, C) => USTM[RespValue]
): USTM[RespValue] =
apply(apply(apply(Some(program.curried))(paramA))(paramB))(paramC).getOrElse(STM.succeedNow(Replies.Error))

private[this] def orMissingParameter4[A, B, C, D](
paramA: Option[A],
paramB: Option[B],
paramC: Option[C],
paramD: Option[D]
)(
program: (A, B, C, D) => USTM[RespValue]
): USTM[RespValue] =
apply(apply(apply(apply(Some(program.curried))(paramA))(paramB))(paramC))(paramD)
.getOrElse(STM.succeedNow(Replies.Error))

Copy link
Member

Choose a reason for hiding this comment

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

As discussed, we can later replace this apply reimplementation with the existing stuff present in zio-prelude.

@mijicd mijicd merged commit 7b9cb2c into zio:master Sep 29, 2021
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.

Add geo api to test executor
2 participants