Skip to content

Instantly share code, notes, and snippets.

def getPartitionStep(parallelism: Int, numberOfPartitions: Int) = parallelism.toDouble / numberOfPartitions
def getEffectivePartitionKeys(maxParallelism: Int, parallelism: Int, numberOfPartitions: Int): Map[Int, Int] = {
val step = getPartitionStep(parallelism, numberOfPartitions)
@tailrec
def findPartitionEffectiveKey(partition: Int, key: Int): Int = {
val keyRange: KeyGroupRange =
KeyGroupRangeAssignment.computeKeyGroupRangeForOperatorIndex(
maxParallelism,
parallelism,
@YuvalItzchakov
YuvalItzchakov / ArrayAgg.scala
Created August 23, 2021 11:37
An attempt to create a generic ARRAY_AGG function for Flink
import org.apache.flink.table.api.DataTypes
import org.apache.flink.table.api.dataview.ListView
import org.apache.flink.table.catalog.DataTypeFactory
import org.apache.flink.table.functions.AggregateFunction
import org.apache.flink.table.types.inference.{ InputTypeStrategies, TypeInference }
import scala.collection.JavaConverters._
import scala.compat.java8.OptionConverters.RichOptionForJava8
import scala.reflect.ClassTag

Keybase proof

I hereby claim:

  • I am yuvalitzchakov on github.
  • I am yuvalitzchakov (https://keybase.io/yuvalitzchakov) on keybase.
  • I have a public key ASCNpDl4BcEt30uHFcNQkS_p_aZKQ7q_1blOJq34f0XoSgo

To claim this, I am signing this object:

@YuvalItzchakov
YuvalItzchakov / HolyShitThisWorks.scala
Created April 15, 2017 16:12
Lazy dropWhile with Cats
package tests
import cats._
import cats.implicits._
import scala.collection.immutable.Stream
/**
* Created by Yuval.Itzchakov on 3/8/2017.
*/
object Test {
scala> Array(1,2,3,4).sliding(2).forall {
| case Array(x, y) => x < y
| case _ => true
| }
res4: Boolean = true
object Yuval extends App {
class Animal {
this: Reflect =>
}
implicit def reflectOrdering: Ordering[Animal with Reflect] = Ordering.by(e => e.canReflect)
object Animal {
def isGreaterAnimal(first: Animal with Reflect, second: Animal with Reflect)(implicit ev: Ordering[Animal with Reflect]) = ev.gt(first, second)
}
[info] +-io.argonaut:argonaut_2.10:6.1
[info] | +-com.github.julien-truffaut:monocle-core_2.10:1.1.0 [S]
[info] | | +-org.scalaz:scalaz-core_2.10:7.1.1 [S] (evicted by: 7.2.0)
[info] | | +-org.scalaz:scalaz-core_2.10:7.2.0 [S]
[info] | |
[info] | +-com.github.julien-truffaut:monocle-macro_2.10:1.1.0 [S]
[info] | | +-com.github.julien-truffaut:monocle-core_2.10:1.1.0 [S]
[info] | | | +-org.scalaz:scalaz-core_2.10:7.1.1 [S] (evicted by: 7.2.0)
[info] | | | +-org.scalaz:scalaz-core_2.10:7.2.0 [S]
[info] | | |
static void GetSize(string msg)
{
byte[] data = Encoding.ASCII.GetBytes(msg);
byte[] sizeinfo = new byte[4];
sizeinfo[0] = (byte)data.Length;
sizeinfo[1] = (byte)(data.Length >> 8);
sizeinfo[2] = (byte)(data.Length >> 16);
sizeinfo[3] = (byte)(data.Length >> 24);
}
List<int> collection = GetCollection();
if ((collection?.Any(x => x > 5))
{
// Is the collection null, or isn't there any element?
}
else
{
// I want to access the list here, need to add a null check:
if (collection != null)
...
public class Program
{
public static void Main(string[] args)
{
new BenchmarkRunner().RunCompetition(new IL_Loops());
}
}
public class IL_Loops
{