Java Code Examples for org.apache.calcite.runtime.SqlFunctions#toLong()

The following examples show how to use org.apache.calcite.runtime.SqlFunctions#toLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeInferenceUtil.java    From marble with Apache License 2.0 4 votes vote down vote up
/**
 * convert the  result of a hive function to the right java object
 *
 * @param objectInspector the outObjectInspector inferred by a hive
 *                        function
 * @param value           the result hive object evaluated by a hive function
 * @return converted calcite object result
 */
public static Object convertHiveObject2CalciteObject(
    ObjectInspector objectInspector,
    Object value) {
  if (value == null) {
    return null;
  }
  if (objectInspector instanceof HiveDecimalObjectInspector) {
    return ((HiveDecimalObjectInspector) objectInspector)
        .getPrimitiveJavaObject(
            value).bigDecimalValue();
  }
  if (objectInspector instanceof DoubleObjectInspector) {
    return ((DoubleObjectInspector) objectInspector).get(value);
  }
  if (objectInspector instanceof IntObjectInspector) {
    return ((IntObjectInspector) objectInspector).get(value);
  }
  if (objectInspector instanceof LongObjectInspector) {
    return ((LongObjectInspector) objectInspector).get(value);
  }
  if (objectInspector instanceof FloatObjectInspector) {
    return ((FloatObjectInspector) objectInspector).get(value);
  }
  if (objectInspector instanceof ShortObjectInspector) {
    return ((ShortObjectInspector) objectInspector).get(value);
  }
  if (objectInspector instanceof StringObjectInspector) {
    return ((StringObjectInspector) objectInspector).getPrimitiveJavaObject(
        value);
  }
  if (objectInspector instanceof BooleanObjectInspector) {
    return ((BooleanObjectInspector) objectInspector).getPrimitiveJavaObject(
        value);
  }
  if (objectInspector instanceof DateObjectInspector) {
    Date date = ((DateObjectInspector) objectInspector)
        .getPrimitiveJavaObject(
            value);
    return SqlFunctions.toInt(date, TimeZone.getTimeZone("UTC"));
  }
  if (objectInspector instanceof TimestampObjectInspector) {
    Timestamp timestamp = ((TimestampObjectInspector) objectInspector)
        .getPrimitiveJavaObject(
            value);
    return SqlFunctions.toLong(timestamp, TimeZone.getTimeZone("UTC"));
  }
  if (objectInspector instanceof StandardListObjectInspector) {
    StandardListObjectInspector standardListObjectInspector =
        (StandardListObjectInspector) objectInspector;
    List<?> list = standardListObjectInspector.getList(value);
    if (list == null) {
      return null;
    }
    ObjectInspector listElementObjectInspector =
        standardListObjectInspector.getListElementObjectInspector();
    List<Object> convertedList = new ArrayList<>();
    for (Object hiveObject : list) {
      convertedList.add(
          convertHiveObject2CalciteObject(listElementObjectInspector,
              hiveObject));
    }
    return convertedList;
  }
  throw new UnsupportedOperationException(
      "fail to convertHiveObject2CalciteObject ,objectInspector="
          + objectInspector
          + ",value="
          + value);
}
 
Example 2
Source File: TypeConvertUtil.java    From marble with Apache License 2.0 4 votes vote down vote up
public static Long toLong(Object value) {
  if (value == null) {
    return null;
  }
  return SqlFunctions.toLong(value);
}
 
Example 3
Source File: Smalls.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static long dateFun(java.sql.Date v) {
  return v == null ? -1L : SqlFunctions.toLong(v);
}
 
Example 4
Source File: Smalls.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static long timestampFun(java.sql.Timestamp v) {
  return v == null ? -1L : SqlFunctions.toLong(v);
}
 
Example 5
Source File: Smalls.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static long timeFun(java.sql.Time v) {
  return v == null ? -1L : SqlFunctions.toLong(v);
}
 
Example 6
Source File: Smalls.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Overloaded functions with DATE, TIMESTAMP and TIME arguments. */
public static long toLong(Date date) {
  return date == null ? 0 : SqlFunctions.toLong(date);
}
 
Example 7
Source File: Smalls.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static long toLong(Timestamp timestamp) {
  return timestamp == null ? 0 : SqlFunctions.toLong(timestamp);
}
 
Example 8
Source File: Smalls.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static long toLong(Time time) {
  return time == null ? 0 : SqlFunctions.toLong(time);
}