Sql 什么是;日期“;在date_sub(日期字符串,int)中,您认为如何?

Sql 什么是;日期“;在date_sub(日期字符串,int)中,您认为如何?,sql,hive,hiveql,Sql,Hive,Hiveql,我遇到了下面这一行,不明白为什么它会起作用 where cast(date_str as date) between date_sub(date '{start_date_str}', 28) and date_sub(date '{start_date_str}', 1) 根据Hive文档,date\u sub的第一个参数应该是字符串。那么,作者为什么要在这两个字符串前面显式地放置一个date关键字呢 是否需要类型转换的语法糖?根据Hive文档,强制转换的正确语法应该是cast(expr

我遇到了下面这一行,不明白为什么它会起作用

where cast(date_str as date) between date_sub(date '{start_date_str}', 28) 
and date_sub(date '{start_date_str}', 1)
根据Hive文档,
date\u sub
的第一个参数应该是字符串。那么,作者为什么要在这两个字符串前面显式地放置一个
date
关键字呢


是否需要类型转换的
语法糖?根据Hive文档,强制转换的正确语法应该是
cast(expr as wanted\u type)
谢谢您的提问。
我刚刚更新了页面


  • ISO/ANSI注释日期文字的方法是
    date'YYYY-MM-DD'
  • 在配置单元开始时,不支持
    日期
    类型,因此日期函数使用
    字符串
    参数

  • 文档似乎已经过时,并且当前除了作为第一个参数的
    字符串
    日期
    时间戳
    之外,都是
    日期
    日期

  • .
    .
    .
    public class GenericUDFDateSub extends GenericUDFDateAdd {
      private transient SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    
      public GenericUDFDateSub() {
        this.signModifier = -1;
      }
    .
    .
    .
    
    .
    .
    .
    switch (inputType1) {
    case STRING:
    case VARCHAR:
    case CHAR:
      inputType1 = PrimitiveCategory.STRING;
      dateConverter = ObjectInspectorConverters.getConverter(
        (PrimitiveObjectInspector) arguments[0],
        PrimitiveObjectInspectorFactory.writableStringObjectInspector);
      break;
    case TIMESTAMP:
      dateConverter = new TimestampConverter((PrimitiveObjectInspector) arguments[0],
        PrimitiveObjectInspectorFactory.writableTimestampObjectInspector);
      break;
    case DATE:
      dateConverter = ObjectInspectorConverters.getConverter(
        (PrimitiveObjectInspector) arguments[0],
        PrimitiveObjectInspectorFactory.writableDateObjectInspector);
      break;
    default:
      throw new UDFArgumentException(
        " DATE_ADD() only takes STRING/TIMESTAMP/DATEWRITABLE types as first argument, got "
        + inputType1);
    }
    .
    .
    .