Analyzes and evaluates expression to an integral value, returned as a long. Throws if the expression cannot be evaluated or if the value evaluates to null. The 'name' parameter is used in exception messages, e.g. "LIMIT expression evaluates to NULL". If 'acceptDate' is true, treat Date expression as
(Analyzer analyzer, String name, boolean acceptDate)
| 1910 | * expression as well. |
| 1911 | */ |
| 1912 | public long evalToInteger(Analyzer analyzer, String name, boolean acceptDate) |
| 1913 | throws AnalysisException { |
| 1914 | // Check for slotrefs and subqueries before analysis so we can provide a more |
| 1915 | // helpful error message. |
| 1916 | if (contains(SlotRef.class) || contains(Subquery.class)) { |
| 1917 | throw new AnalysisException(name + " expression must be a constant expression: " + |
| 1918 | toSql()); |
| 1919 | } |
| 1920 | analyze(analyzer); |
| 1921 | if (!isConstant()) { |
| 1922 | throw new AnalysisException(name + " expression must be a constant expression: " + |
| 1923 | toSql()); |
| 1924 | } |
| 1925 | if (!getType().isIntegerType() && !(acceptDate && getType().isDate())) { |
| 1926 | throw new AnalysisException(name + " expression must be an integer type but is '" + |
| 1927 | getType() + "': " + toSql()); |
| 1928 | } |
| 1929 | TColumnValue val = null; |
| 1930 | try { |
| 1931 | val = FeSupport.EvalExprWithoutRow(this, analyzer.getQueryCtx()); |
| 1932 | } catch (InternalException e) { |
| 1933 | throw new AnalysisException("Failed to evaluate expr: " + toSql(), e); |
| 1934 | } |
| 1935 | |
| 1936 | try { |
| 1937 | return evalToInteger(val, acceptDate); |
| 1938 | } catch (AnalysisException e) { |
| 1939 | throw new AnalysisException(name + " expression evaluates to NULL: " + toSql()); |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | public static long evalToInteger(TColumnValue val, boolean acceptDate) |
| 1944 | throws AnalysisException { |
no test coverage detected