def ranges()

in spark/hbase-spark/src/main/scala/org/apache/hadoop/hbase/spark/datasources/NaiveEncoder.scala [82:191]


  def ranges(in: Any): Option[BoundRanges] = in match {
    case a: Integer =>
      val b = Bytes.toBytes(a)
      if (a >= 0) {
        logDebug(s"range is 0 to $a and ${Integer.MIN_VALUE} to -1")
        Some(
          BoundRanges(
            Array(
              BoundRange(Bytes.toBytes(0: Int), b),
              BoundRange(Bytes.toBytes(Integer.MIN_VALUE), Bytes.toBytes(-1: Int))),
            Array(BoundRange(b, Bytes.toBytes(Integer.MAX_VALUE))),
            b))
      } else {
        Some(
          BoundRanges(
            Array(BoundRange(Bytes.toBytes(Integer.MIN_VALUE), b)),
            Array(
              BoundRange(b, Bytes.toBytes(-1: Integer)),
              BoundRange(Bytes.toBytes(0: Int), Bytes.toBytes(Integer.MAX_VALUE))),
            b))
      }
    case a: Long =>
      val b = Bytes.toBytes(a)
      if (a >= 0) {
        Some(
          BoundRanges(
            Array(
              BoundRange(Bytes.toBytes(0: Long), b),
              BoundRange(Bytes.toBytes(Long.MinValue), Bytes.toBytes(-1: Long))),
            Array(BoundRange(b, Bytes.toBytes(Long.MaxValue))),
            b))
      } else {
        Some(
          BoundRanges(
            Array(BoundRange(Bytes.toBytes(Long.MinValue), b)),
            Array(
              BoundRange(b, Bytes.toBytes(-1: Long)),
              BoundRange(Bytes.toBytes(0: Long), Bytes.toBytes(Long.MaxValue))),
            b))
      }
    case a: Short =>
      val b = Bytes.toBytes(a)
      if (a >= 0) {
        Some(
          BoundRanges(
            Array(
              BoundRange(Bytes.toBytes(0: Short), b),
              BoundRange(Bytes.toBytes(Short.MinValue), Bytes.toBytes(-1: Short))),
            Array(BoundRange(b, Bytes.toBytes(Short.MaxValue))),
            b))
      } else {
        Some(
          BoundRanges(
            Array(BoundRange(Bytes.toBytes(Short.MinValue), b)),
            Array(
              BoundRange(b, Bytes.toBytes(-1: Short)),
              BoundRange(Bytes.toBytes(0: Short), Bytes.toBytes(Short.MaxValue))),
            b))
      }
    case a: Double =>
      val b = Bytes.toBytes(a)
      if (a >= 0.0f) {
        Some(
          BoundRanges(
            Array(
              BoundRange(Bytes.toBytes(0.0d), b),
              BoundRange(Bytes.toBytes(-0.0d), Bytes.toBytes(Double.MinValue))),
            Array(BoundRange(b, Bytes.toBytes(Double.MaxValue))),
            b))
      } else {
        Some(
          BoundRanges(
            Array(BoundRange(b, Bytes.toBytes(Double.MinValue))),
            Array(
              BoundRange(Bytes.toBytes(-0.0d), b),
              BoundRange(Bytes.toBytes(0.0d), Bytes.toBytes(Double.MaxValue))),
            b))
      }
    case a: Float =>
      val b = Bytes.toBytes(a)
      if (a >= 0.0f) {
        Some(
          BoundRanges(
            Array(
              BoundRange(Bytes.toBytes(0.0f), b),
              BoundRange(Bytes.toBytes(-0.0f), Bytes.toBytes(Float.MinValue))),
            Array(BoundRange(b, Bytes.toBytes(Float.MaxValue))),
            b))
      } else {
        Some(
          BoundRanges(
            Array(BoundRange(b, Bytes.toBytes(Float.MinValue))),
            Array(
              BoundRange(Bytes.toBytes(-0.0f), b),
              BoundRange(Bytes.toBytes(0.0f), Bytes.toBytes(Float.MaxValue))),
            b))
      }
    case a: Array[Byte] =>
      Some(BoundRanges(Array(BoundRange(bytesMin, a)), Array(BoundRange(a, bytesMax)), a))
    case a: Byte =>
      val b = Array(a)
      Some(BoundRanges(Array(BoundRange(bytesMin, b)), Array(BoundRange(b, bytesMax)), b))
    case a: String =>
      val b = Bytes.toBytes(a)
      Some(BoundRanges(Array(BoundRange(bytesMin, b)), Array(BoundRange(b, bytesMax)), b))
    case a: UTF8String =>
      val b = a.getBytes
      Some(BoundRanges(Array(BoundRange(bytesMin, b)), Array(BoundRange(b, bytesMax)), b))
    case _ => None
  }