HIVE WHERE NOT EXISTS doesn't compare NULLS

时间:2017-08-30 20:34:09

标签: sql hive hql hiveql

I am trying to select only the rows where some of the column values differ. My problem is that if I use =, it doesn't compare columns with null values and if I replace = with Like, I get the following error, Any suggestions? Both tables have columns that are equivalent

Unsupported SubQuery Expression SubQuery expression refers to both Parent and SubQuery expressions and is not a valid join condition. (state=42000,code=10249)

namespace ADL_Hack {
    template <typename T>
    struct allocator : std::allocator<T> { };
}

template <typename T>
using Vector = std::vector<T, ADL_Hack::allocator<T> >;

namespace ADL_Hack {
    template <typename... Ts>
    std::ostream &operator<<(std::ostream &os, std::vector<Ts...> const &art) {
        os << "[";
        for (auto it = art.begin(); it != art.end(); it++) {
            os << *it << ",";
        }
        os << "]";
        return os;
    }
}

2 个答案:

答案 0 :(得分:0)

select  t.* 

from                table1 t

        left join   table2 l 

        on          t.loco_id   <=> l.loco_id 
                and t.a         <=> l.a 
                and t.b         <=> l.b

where   l.loco_id is null
;
  

A&lt; =&gt;乙
  对于非null,使用EQUAL(=)运算符返回相同的结果   操作数,但如果两者都为NULL则返回TRUE,如果其中之一则返回FALSE   一片空白。 (从0.9.0版开始。)

     

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-RelationalOperators

答案 1 :(得分:-1)

@search_productos_out = Producto.without_grupo(params[:id],params[:IdEmpresa]) is technically means its scope :without_grupo, -> (id_grupo, id_empresa) {Producto.includes(:relprogrupos).references(:relprogrupos).where("relprogrupos.id IS NULL OR productos.Clave not in (select distinct ProductoId from relprogrupos where IdGrupo = ?) AND relprogrupos.IdEmpresa != ?", id_grupo, id_empresa)}

/env doesn't compare null-s; because its impossible to compare them...the result of the comparision of two unknown is =:

unknown

however:

unknowns

will fail, because the result is unknown(null).

If you still want to join by using select assert_true( (null = null) is null ) -s; I would recommend to add some select assert_true( (null = null) ) -s to get rid of these unknown-s.