FAQ
Author: cws
Date: Tue Jul 26 22:28:33 2011
New Revision: 1151280

URL: http://svn.apache.org/viewvc?rev=1151280&view=rev
Log:
HIVE-2256. Better error message in CLI on invalid column name (Sohan Jain via cws)

Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/RowResolver.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDAFPercentile.java
hive/trunk/ql/src/test/results/clientnegative/clustern4.q.out
hive/trunk/ql/src/test/results/clientnegative/input2.q.out
hive/trunk/ql/src/test/results/clientnegative/regex_col_groupby.q.out
hive/trunk/ql/src/test/results/clientnegative/semijoin1.q.out
hive/trunk/ql/src/test/results/clientnegative/semijoin2.q.out
hive/trunk/ql/src/test/results/clientnegative/semijoin3.q.out
hive/trunk/ql/src/test/results/clientnegative/semijoin4.q.out
hive/trunk/ql/src/test/results/compiler/errors/unknown_column4.q.out
hive/trunk/ql/src/test/results/compiler/errors/unknown_column5.q.out

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/RowResolver.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/RowResolver.java?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/RowResolver.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/RowResolver.java Tue Jul 26 22:28:33 2011
@@ -22,6 +22,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;

@@ -167,6 +168,26 @@ public class RowResolver implements Seri
return rowSchema.getSignature();
}

+ /**
+ * Get a list of non-hidden column names
+ * @param max the maximum number of columns to return
+ * @return a list of non-hidden column names no greater in size than max
+ */
+ public List<String> getNonHiddenColumnNames(int max) {
+ List<String> columnNames = new ArrayList<String>();
+ int count = 0;
+ for (ColumnInfo columnInfo : getColumnInfos()) {
+ if (max > 0 && count >= max) {
+ break;
+ }
+ if (!columnInfo.isHiddenVirtualCol()) {
+ columnNames.add(columnInfo.getInternalName());
+ count++;
+ }
+ }
+ return columnNames;
+ }
+
public HashMap<String, ColumnInfo> getFieldMap(String tabAlias) {
if (tabAlias == null) {
return rslvMap.get(null);

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java Tue Jul 26 22:28:33 2011
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Stack;

+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.ColumnInfo;
@@ -395,8 +396,11 @@ public final class TypeCheckProcFactory
ctx.setError(ErrorMsg.NON_KEY_EXPR_IN_GROUPBY.getMsg(exprNode), expr);
return null;
} else {
- ctx.setError(ErrorMsg.INVALID_TABLE_OR_COLUMN.getMsg(expr
- .getChild(0)), expr);
+ List<String> possibleColumnNames = input.getNonHiddenColumnNames(-1);
+ String reason = String.format("(possible column names are: %s)",
+ StringUtils.join(possibleColumnNames, ", "));
+ ctx.setError(ErrorMsg.INVALID_TABLE_OR_COLUMN.getMsg(expr.getChild(0), reason),
+ expr);
LOG.debug(ErrorMsg.INVALID_TABLE_OR_COLUMN.toString() + ":"
+ input.toString());
return null;

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDAFPercentile.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDAFPercentile.java?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDAFPercentile.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDAFPercentile.java Tue Jul 26 22:28:33 2011
@@ -234,12 +234,18 @@ public class UDAFPercentile extends UDAF

public boolean iterate(LongWritable o, List<DoubleWritable> percentiles) {
if (state.percentiles == null) {
- for (int i = 0; i < percentiles.size(); i++) {
- if (percentiles.get(i).get() < 0.0 || percentiles.get(i).get() > 1.0) {
- throw new RuntimeException("Percentile value must be wihin the range of 0 to 1.");
- }
+ if(percentiles != null) {
+ for (int i = 0; i < percentiles.size(); i++) {
+ if (percentiles.get(i).get() < 0.0 || percentiles.get(i).get() > 1.0) {
+ throw new RuntimeException("Percentile value must be wihin the range of 0 to 1.");
+ }
+ }
+
+ state.percentiles = new ArrayList<DoubleWritable>(percentiles);
+ }
+ else {
+ state.percentiles = new ArrayList<DoubleWritable>();
}
- state.percentiles = new ArrayList<DoubleWritable>(percentiles);
}
if (o != null) {
increment(state, o, 1);

Modified: hive/trunk/ql/src/test/results/clientnegative/clustern4.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/clustern4.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/clustern4.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/clustern4.q.out Tue Jul 26 22:28:33 2011
@@ -1 +1 @@
-FAILED: Error in semantic analysis: Line 2:50 Invalid table alias or column reference 'key'
+FAILED: Error in semantic analysis: Line 2:50 Invalid table alias or column reference 'key': (possible column names are: _col0, _col1)

Modified: hive/trunk/ql/src/test/results/clientnegative/input2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/input2.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/input2.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/input2.q.out Tue Jul 26 22:28:33 2011
@@ -1 +1 @@
-FAILED: Error in semantic analysis: Line 1:7 Invalid table alias or column reference 'a'
+FAILED: Error in semantic analysis: Line 1:7 Invalid table alias or column reference 'a': (possible column names are: key, value)

Modified: hive/trunk/ql/src/test/results/clientnegative/regex_col_groupby.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/regex_col_groupby.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/regex_col_groupby.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/regex_col_groupby.q.out Tue Jul 26 22:28:33 2011
@@ -1 +1 @@
-FAILED: Error in semantic analysis: Line 2:44 Invalid table alias or column reference '`..`'
+FAILED: Error in semantic analysis: Line 2:44 Invalid table alias or column reference '`..`': (possible column names are: key, value, ds, hr)

Modified: hive/trunk/ql/src/test/results/clientnegative/semijoin1.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/semijoin1.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/semijoin1.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/semijoin1.q.out Tue Jul 26 22:28:33 2011
@@ -1 +1 @@
-FAILED: Error in semantic analysis: Line 2:7 Invalid table alias or column reference 'b'
+FAILED: Error in semantic analysis: Line 2:7 Invalid table alias or column reference 'b': (possible column names are: _col0, _col1)

Modified: hive/trunk/ql/src/test/results/clientnegative/semijoin2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/semijoin2.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/semijoin2.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/semijoin2.q.out Tue Jul 26 22:28:33 2011
@@ -1 +1 @@
-FAILED: Error in semantic analysis: Line 2:70 Invalid table alias or column reference 'b'
+FAILED: Error in semantic analysis: Line 2:70 Invalid table alias or column reference 'b': (possible column names are: _col0, _col1)

Modified: hive/trunk/ql/src/test/results/clientnegative/semijoin3.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/semijoin3.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/semijoin3.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/semijoin3.q.out Tue Jul 26 22:28:33 2011
@@ -1 +1 @@
-FAILED: Error in semantic analysis: Line 2:67 Invalid table alias or column reference 'b'
+FAILED: Error in semantic analysis: Line 2:67 Invalid table alias or column reference 'b': (possible column names are: _col0, _col1)

Modified: hive/trunk/ql/src/test/results/clientnegative/semijoin4.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/semijoin4.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/semijoin4.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/semijoin4.q.out Tue Jul 26 22:28:33 2011
@@ -1 +1 @@
-FAILED: Error in semantic analysis: Line 2:112 Invalid table alias or column reference 'b'
+FAILED: Error in semantic analysis: Line 2:112 Invalid table alias or column reference 'b': (possible column names are: _col0, _col1)

Modified: hive/trunk/ql/src/test/results/compiler/errors/unknown_column4.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/compiler/errors/unknown_column4.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/compiler/errors/unknown_column4.q.out (original)
+++ hive/trunk/ql/src/test/results/compiler/errors/unknown_column4.q.out Tue Jul 26 22:28:33 2011
@@ -1,2 +1,2 @@
Semantic Exception:
-Line 2:83 Invalid table alias or column reference 'dummysrc'
\ No newline at end of file
+Line 2:83 Invalid table alias or column reference 'dummysrc': (possible column names are: key, value)
\ No newline at end of file

Modified: hive/trunk/ql/src/test/results/compiler/errors/unknown_column5.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/compiler/errors/unknown_column5.q.out?rev=1151280&r1=1151279&r2=1151280&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/compiler/errors/unknown_column5.q.out (original)
+++ hive/trunk/ql/src/test/results/compiler/errors/unknown_column5.q.out Tue Jul 26 22:28:33 2011
@@ -1,2 +1,2 @@
Semantic Exception:
-Line 2:60 Invalid table alias or column reference 'dummysrc'
\ No newline at end of file
+Line 2:60 Invalid table alias or column reference 'dummysrc': (possible column names are: key, value)
\ No newline at end of file

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categorieshive, hadoop
postedJul 26, '11 at 10:28p
activeJul 26, '11 at 10:28p
posts1
users1
websitehive.apache.org

1 user in discussion

Cws: 1 post

People

Translate

site design / logo © 2021 Grokbase