-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 0.14 scalafix migration for saveAsAvroFile and update avro coder one
- Loading branch information
1 parent
6b44dd2
commit 21f6e3f
Showing
16 changed files
with
150 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
scalafix/input-0_14/src/main/scala/fix/v0_14_0/AvroRecords.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
rule = FixAvroCoder | ||
*/ | ||
package fix.v0_14_0 | ||
|
||
import org.apache.avro.Schema | ||
import org.apache.avro.specific.{SpecificFixed, SpecificRecord} | ||
|
||
import java.io.{ObjectInput, ObjectOutput} | ||
|
||
class A extends SpecificRecord { | ||
override def put(i: Int, v: Any): Unit = ??? | ||
override def get(i: Int): AnyRef = ??? | ||
override def getSchema: Schema = ??? | ||
} | ||
|
||
class B extends SpecificFixed { | ||
override def getSchema: Schema = ??? | ||
override def writeExternal(out: ObjectOutput): Unit = ??? | ||
override def readExternal(in: ObjectInput): Unit = ??? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
scalafix/input-0_14/src/main/scala/fix/v0_14_0/FixGenericAvro.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
rule = FixGenericAvro | ||
*/ | ||
package fix.v0_14_0 | ||
|
||
import com.spotify.scio.avro._ | ||
import com.spotify.scio.values.SCollection | ||
import org.apache.avro.Schema | ||
import org.apache.avro.generic.GenericRecord | ||
|
||
object FixGenericAvro { | ||
|
||
val path: String = ??? | ||
val numShards: Int = ??? | ||
val schema: Schema = ??? | ||
val suffix: String = ??? | ||
|
||
val sc: SCollection[GenericRecord] = ??? | ||
|
||
|
||
sc.saveAsAvroFile(path, numShards, schema) | ||
sc.saveAsAvroFile(path, numShards, schema, suffix) | ||
sc.saveAsAvroFile(path, numShards, suffix = suffix, schema = schema) | ||
|
||
// should not be touched | ||
sc.saveAsAvroFile(path, schema = schema, numShards = numShards) | ||
sc.saveAsAvroFile(path, schema = schema) | ||
sc.saveAsAvroFile(numShards = numShards, schema = schema, path = path) | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
scalafix/output-0_14/src/main/scala/fix/v0_14_0/AvroRecords.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
package fix.v0_14_0 | ||
|
||
import org.apache.avro.Schema | ||
import org.apache.avro.specific.{SpecificFixed, SpecificRecord} | ||
|
||
import java.io.{ObjectInput, ObjectOutput} | ||
|
||
class A extends SpecificRecord { | ||
override def put(i: Int, v: Any): Unit = ??? | ||
override def get(i: Int): AnyRef = ??? | ||
override def getSchema: Schema = ??? | ||
} | ||
|
||
class B extends SpecificFixed { | ||
override def getSchema: Schema = ??? | ||
override def writeExternal(out: ObjectOutput): Unit = ??? | ||
override def readExternal(in: ObjectInput): Unit = ??? | ||
} |
10 changes: 1 addition & 9 deletions
10
scalafix/output-0_14/src/main/scala/fix/v0_14_0/FixAvroCoder1.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
|
||
package fix.v0_14_0 | ||
|
||
import org.apache.avro.specific.SpecificFixed | ||
import org.apache.avro.{Schema => AvroSchema} | ||
import java.io.{ObjectInput, ObjectOutput} | ||
import com.spotify.scio.avro._ | ||
|
||
class B extends SpecificFixed { | ||
override def getSchema: AvroSchema = ??? | ||
override def writeExternal(out: ObjectOutput): Unit = ??? | ||
override def readExternal(in: ObjectInput): Unit = ??? | ||
} | ||
|
||
object FixAvroCoder1 { | ||
val schema: AvroSchema = ??? | ||
avroGenericRecordCoder | ||
avroGenericRecordCoder(schema) | ||
avroSpecificRecordCoder[A] | ||
avroSpecificFixedCoder[B] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
scalafix/output-0_14/src/main/scala/fix/v0_14_0/FixGenericAvro.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
package fix.v0_14_0 | ||
|
||
import com.spotify.scio.avro._ | ||
import com.spotify.scio.values.SCollection | ||
import org.apache.avro.Schema | ||
import org.apache.avro.generic.GenericRecord | ||
|
||
object FixGenericAvro { | ||
|
||
val path: String = ??? | ||
val numShards: Int = ??? | ||
val schema: Schema = ??? | ||
val suffix: String = ??? | ||
|
||
val sc: SCollection[GenericRecord] = ??? | ||
|
||
|
||
sc.saveAsAvroFile(path, schema, numShards) | ||
sc.saveAsAvroFile(path, schema, numShards, suffix) | ||
sc.saveAsAvroFile(path, numShards = numShards, suffix = suffix, schema = schema) | ||
|
||
// should not be touched | ||
sc.saveAsAvroFile(path, schema = schema, numShards = numShards) | ||
sc.saveAsAvroFile(path, schema = schema) | ||
sc.saveAsAvroFile(numShards = numShards, schema = schema, path = path) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
scalafix/rules/src/main/scala/fix/v0_14_0/FixGenericAvro.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package fix.v0_14_0 | ||
|
||
import scalafix.v1._ | ||
|
||
import scala.meta._ | ||
|
||
object FixGenericAvro { | ||
private val AvroGenericSaveMatcher = SymbolMatcher.normalized( | ||
"com/spotify/scio/avro/syntax/GenericRecordSCollectionOps#saveAsAvroFile" | ||
) | ||
} | ||
|
||
class FixGenericAvro extends SemanticRule("FixGenericAvro") { | ||
import FixGenericAvro._ | ||
|
||
override def fix(implicit doc: SemanticDocument): Patch = { | ||
doc.tree.collect { | ||
case t @ q"$fn(..$params)" if AvroGenericSaveMatcher.matches(fn.symbol) => | ||
params.toList match { | ||
case _ :: q"$_ = $_" :: _ => | ||
// 2nd params is already named | ||
Patch.empty | ||
case path :: numShards :: (next @ q"$name = $_") :: tail if name.syntax != "schema" => | ||
// 3rd param is named but not schema | ||
val named = path :: q"numShards = $numShards" :: next :: tail | ||
Patch.replaceTree(t, q"$fn(..$named)".syntax) | ||
case path :: numShards :: schema :: tail => | ||
val reordered = path :: schema :: numShards :: tail | ||
Patch.replaceTree(t, q"$fn(..$reordered)".syntax) | ||
case _ => | ||
Patch.empty | ||
} | ||
}.asPatch | ||
} | ||
} |