Skip to content

Commit

Permalink
resolve scalastyle
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhou-db committed Aug 19, 2023
1 parent 7d7edd5 commit 86ebbaf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,31 +210,29 @@ class DeltaSharingRestClientSuite extends DeltaSharingIntegrationTest {
format = Format(),
schemaString = """{"type":"struct","fields":[{"name":"name","type":"string","nullable":false,"metadata":{}}]}""",
configuration = Map("enableChangeDataFeed" -> "true"),
partitionColumns = Nil)
val responseV0 =
client.getMetadata(
Table(name = "streaming_notnull_to_null", schema = "default", share = "share8"),
versionAsOf = Some(0)
)
partitionColumns = Nil
)
val responseV0 = client.getMetadata(
Table(name = "streaming_notnull_to_null", schema = "default", share = "share8"),
versionAsOf = Some(0)
)
assert(Protocol(minReaderVersion = 1) == responseV0.protocol)
assert(metadataV0 == responseV0.metadata)

val metadataV2 = metadataV0.copy(
schemaString = """{"type":"struct","fields":[{"name":"name","type":"string","nullable":true,"metadata":{}}]}""",
)
val responseV2 =
client.getMetadata(
Table(name = "streaming_notnull_to_null", schema = "default", share = "share8"),
versionAsOf = Some(2)
)
val responseV2 = client.getMetadata(
Table(name = "streaming_notnull_to_null", schema = "default", share = "share8"),
versionAsOf = Some(2)
)
assert(Protocol(minReaderVersion = 1) == responseV0.protocol)
assert(metadataV2 == responseV2.metadata)

val responseTimestamp =
client.getMetadata(
Table(name = "streaming_notnull_to_null", schema = "default", share = "share8"),
timestampAsOf = Some("2022-11-13T08:10:50Z")
)
val responseTimestamp = client.getMetadata(
Table(name = "streaming_notnull_to_null", schema = "default", share = "share8"),
timestampAsOf = Some("2022-11-13T08:10:50Z")
)
assert(Protocol(minReaderVersion = 1) == responseV0.protocol)
assert(metadataV2 == responseTimestamp.metadata)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1941,21 +1941,7 @@ class DeltaSharingServiceSuite extends FunSuite with BeforeAndAfterAll {
assert(expectedMetadata == actions(1).metaData)
}

integrationTest("streaming_notnull_to_null - metadata of different versions") {
def getMetadataResponse(version: Long): String = {
readNDJson(
requestPath(s"/shares/share8/schemas/default/tables/streaming_notnull_to_null/metadata?version=$version"),
expectedTableVersion = Some(version)
)
}
def verifyMetadata(version: Long, expectedMetadata: Metadata): Unit = {
val response = getMetadataResponse(version)
val Array(protocol, metadata) = response.split("\n")
val expectedProtocol = Protocol(minReaderVersion = 1)
assert(expectedProtocol.wrap == JsonUtils.fromJson[SingleAction](protocol))
assert(expectedMetadata.wrap == JsonUtils.fromJson[SingleAction](metadata))
}

object StreamingNotnullToNull {
val metadataV0 = Metadata(
id = "1e2201ff-12ad-4c3b-a539-4d34e9e36680",
format = Format(),
Expand All @@ -1966,11 +1952,28 @@ class DeltaSharingServiceSuite extends FunSuite with BeforeAndAfterAll {
val metadataV2 = metadataV0.copy(
schemaString = """{"type":"struct","fields":[{"name":"name","type":"string","nullable":true,"metadata":{}}]}""",
)
}

def getMetadataResponse(version: Long): String = {
readNDJson(
requestPath(s"/shares/share8/schemas/default/tables/streaming_notnull_to_null/metadata?version=$version"),
expectedTableVersion = Some(version)
)
}

verifyMetadata(0, metadataV0)
verifyMetadata(1, metadataV0)
verifyMetadata(2, metadataV2)
verifyMetadata(3, metadataV2)
def verifyMetadata(version: Long, expectedMetadata: Metadata): Unit = {
val response = getMetadataResponse(version)
val Array(protocol, metadata) = response.split("\n")
val expectedProtocol = Protocol(minReaderVersion = 1)
assert(expectedProtocol.wrap == JsonUtils.fromJson[SingleAction](protocol))
assert(expectedMetadata.wrap == JsonUtils.fromJson[SingleAction](metadata))
}

integrationTest("streaming_notnull_to_null - metadata of different versions") {
verifyMetadata(0, StreamingNotnullToNull.metadataV0)
verifyMetadata(1, StreamingNotnullToNull.metadataV0)
verifyMetadata(2, StreamingNotnullToNull.metadataV2)
verifyMetadata(3, StreamingNotnullToNull.metadataV2)
assertHttpError(
url = requestPath(s"/shares/share8/schemas/default/tables/streaming_notnull_to_null/metadata?version=4"),
method = "GET",
Expand All @@ -1980,37 +1983,26 @@ class DeltaSharingServiceSuite extends FunSuite with BeforeAndAfterAll {
)
}

integrationTest("streaming_notnull_to_null - metadata of different timestamp") {
def getMetadataResponse(timestamp: String, version: Long): String = {
readNDJson(
requestPath(s"/shares/share8/schemas/default/tables/streaming_notnull_to_null/metadata?timestamp=$timestamp"),
expectedTableVersion = Some(version)
)
}

def verifyMetadata(timestamp: String, version: Long, expectedMetadata: Metadata): Unit = {
val response = getMetadataResponse(timestamp, version)
val Array(protocol, metadata) = response.split("\n")
val expectedProtocol = Protocol(minReaderVersion = 1)
assert(expectedProtocol.wrap == JsonUtils.fromJson[SingleAction](protocol))
assert(expectedMetadata.wrap == JsonUtils.fromJson[SingleAction](metadata))
}

val metadataV0 = Metadata(
id = "1e2201ff-12ad-4c3b-a539-4d34e9e36680",
format = Format(),
schemaString = """{"type":"struct","fields":[{"name":"name","type":"string","nullable":false,"metadata":{}}]}""",
configuration = Map("enableChangeDataFeed" -> "true"),
partitionColumns = Nil
)
val metadataV2 = metadataV0.copy(
schemaString = """{"type":"struct","fields":[{"name":"name","type":"string","nullable":true,"metadata":{}}]}""",
def getMetadataResponse(timestamp: String, version: Long): String = {
readNDJson(
requestPath(s"/shares/share8/schemas/default/tables/streaming_notnull_to_null/metadata?timestamp=$timestamp"),
expectedTableVersion = Some(version)
)
}

verifyMetadata("2022-11-13T08:10:41Z", 0, metadataV0)
verifyMetadata("2022-11-13T08:10:46Z", 1, metadataV0)
verifyMetadata("2022-11-13T08:10:48Z", 2, metadataV2)
verifyMetadata("2022-11-13T08:10:50Z", 3, metadataV2)
def verifyMetadata(timestamp: String, version: Long, expectedMetadata: Metadata): Unit = {
val response = getMetadataResponse(timestamp, version)
val Array(protocol, metadata) = response.split("\n")
val expectedProtocol = Protocol(minReaderVersion = 1)
assert(expectedProtocol.wrap == JsonUtils.fromJson[SingleAction](protocol))
assert(expectedMetadata.wrap == JsonUtils.fromJson[SingleAction](metadata))
}

integrationTest("streaming_notnull_to_null - metadata of different timestamp") {
verifyMetadata("2022-11-13T08:10:41Z", 0, StreamingNotnullToNull.metadataV0)
verifyMetadata("2022-11-13T08:10:46Z", 1, StreamingNotnullToNull.metadataV0)
verifyMetadata("2022-11-13T08:10:48Z", 2, StreamingNotnullToNull.metadataV2)
verifyMetadata("2022-11-13T08:10:50Z", 3, StreamingNotnullToNull.metadataV2)
assertHttpError(
url = requestPath(s"/shares/share8/schemas/default/tables/streaming_notnull_to_null/metadata?timestamp=2021-01-01"),
method = "GET",
Expand Down

0 comments on commit 86ebbaf

Please sign in to comment.