osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Select on dynamic table, column "**" is ambiguous


I need help to find how to solve this issue. 

I created a class extending AbstractQueryableTable which implements TranslatableTable and CustomColumnResolvingTable. 
I managed to perform query by specifying the fields like : 
String query = "select name,ID,My_Metadata:field FROM Document WHERE ID=1234 LIMIT 10"; 

However when I'm trying this query : 
String query = "select * FROM Document "; 

I have a column ambiguous exception. It's because the method "resolveColumn" from CustomColumnResolvingTable is waiting a specific field. But I want all the fields that are present in my table. 

Here's the relevant code : 

public class MyClassBaseTable extends AbstractQueryableTable implements TranslatableTable, CustomColumnResolvingTable { 
....... 
// Useful method to retrieve metadata if there's any. Otherwise just get the original field 
private Pair<RelDataTypeField, List<String>> resolveColumn(String name, RelDataTypeFactory typeFactory){ 
List<RelDataTypeField> fields = rowType.getFieldList(); 
boolean exist = false; 
for (RelDataTypeField f : fields) { 
if (Util.matches(true, f.getName(), name)) { 
exist = true; 
break; 
} 
} 
RelDataTypeField field = rowType.getField(name, false, false); 
if (exist){ 
field = rowType.getField(name, true, false); 
} 
else { 
if (rowType instanceof DynamicRecordTypeImpl) { 
field = new RelDataTypeFieldImpl(name, fields.size(), ESFieldType.T.toType(typeFactory)); 
fields.add(field); 
table.fieldTypes.add(new ESField(name, table.getName().getTemplate()+"/MetaData/:"+name.replace(":", "/"), ESFieldType.T)); 
} 
} 
return new Pair<>(field, Collections.emptyList()); 
} 


@Override 
public List<Pair<RelDataTypeField, List<String>>> resolveColumn(RelDataType rowType, RelDataTypeFactory typeFactory, List<String> names) { 
String name = names.get(0); 
// THIS PART WAS ADDED BUT IT S NOT WORKING 
if ("**".equals(name)) { 
List<RelDataTypeField> fields = rowType.getFieldList(); 
List<Pair<RelDataTypeField, List<String>>> result = new ArrayList<>(fields.size()); 

for (RelDataTypeField field:fields) { 
result.add(new Pair<>(field, Collections.emptyList())); 
} 
return result; 
} 
else { 
return new ArrayList<>(Collections.singleton(resolveColumn(name, typeFactory))); 
} 
} 
......... 
} 

And the relevant stack trace : 

Caused by: org.apache.calcite.runtime.CalciteContextException: At line 1, column 8: Column '**' is ambiguous 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) 
at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:783) 
at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:768) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:4759) 
at org.apache.calcite.sql.validate.DelegatingScope.fullyQualify(DelegatingScope.java:467) 
at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5507) 
at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5470) 
at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:334) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1629) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1614) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.addToSelectList(SqlValidatorImpl.java:1827) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(SqlValidatorImpl.java:489) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:422) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4023) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3286) 
at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60) 
at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:967) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:943) 
at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:225) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:918) 
at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:628) 
at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:552) 
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) 
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) 
at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772) 
at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636) 
at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:606) 
at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229) 
at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550) 
at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675) 
at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156) 
... 30 more 
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Column '**' is ambiguous 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) 
at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572) 
... 61 more