-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use source lookup for analyzed columns in whereClause if inside funct…
…ions -> where substr(analyzed_text, 1,1) = 'x' threw GroupByOnArrayUnsupported exception, now it works correctly using source lookup
- Loading branch information
1 parent
bbf7fa5
commit a4db868
Showing
24 changed files
with
214 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 0 additions & 88 deletions
88
sql/src/main/java/io/crate/metadata/DocReferenceBuildingVisitor.java
This file was deleted.
Oops, something went wrong.
129 changes: 129 additions & 0 deletions
129
sql/src/main/java/io/crate/metadata/DocReferenceConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Licensed to CRATE Technology GmbH ("Crate") under one or more contributor | ||
* license agreements. See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. Crate licenses | ||
* this file to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may | ||
* obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* However, if you have executed another commercial license agreement | ||
* with Crate these terms will supersede the license and you may use the | ||
* software solely pursuant to the terms of the relevant commercial agreement. | ||
*/ | ||
|
||
package io.crate.metadata; | ||
|
||
import com.google.common.base.Predicate; | ||
import io.crate.metadata.doc.DocSchemaInfo; | ||
import io.crate.metadata.doc.DocSysColumns; | ||
import io.crate.metadata.table.TableInfo; | ||
import io.crate.planner.symbol.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Visitor to change regular column references into references using the DOC sys column. | ||
* | ||
* e.g. s.t.colname -> s.t._DOC['colname'] | ||
*/ | ||
public class DocReferenceConverter { | ||
|
||
private final static SafeVisitor SAFE_VISITOR = new SafeVisitor(); | ||
private final static PredicateVisitor PREDICATE_VISITOR = new PredicateVisitor(); | ||
|
||
/** | ||
* re-writes any references to source lookup ( n -> _doc['n'] ) | ||
* | ||
* won't be converted: partition columns or non-doc-schema columns | ||
*/ | ||
public static Symbol convertIfPossible(Symbol symbol, TableInfo tableInfo) { | ||
return SAFE_VISITOR.process(symbol, tableInfo); | ||
} | ||
|
||
/** | ||
* will convert any references that are analyzed or not indexed to doc-references | ||
*/ | ||
public static Symbol convertIf(Symbol symbol, Predicate<Reference> predicate) { | ||
return PREDICATE_VISITOR.process(symbol, predicate); | ||
} | ||
|
||
private static class Visitor<T> extends SymbolVisitor<T, Symbol> { | ||
|
||
@Override | ||
public Symbol visitFunction(Function symbol, T context) { | ||
int idx = 0; | ||
for (Symbol argument : symbol.arguments()) { | ||
symbol.setArgument(idx, process(argument, context)); | ||
idx++; | ||
} | ||
return symbol; | ||
} | ||
|
||
@Override | ||
public Symbol visitDynamicReference(DynamicReference symbol, T context) { | ||
return visitReference(symbol, context); | ||
} | ||
|
||
@Override | ||
protected Symbol visitSymbol(Symbol symbol, T context) { | ||
return symbol; | ||
} | ||
} | ||
|
||
private static Reference toSourceLookup(Reference reference) { | ||
ReferenceIdent ident = reference.info().ident(); | ||
List<String> path = new ArrayList<>(ident.columnIdent().path()); | ||
if (path.isEmpty()) { // if it's empty it might be an empty immutableList | ||
path = Arrays.asList(ident.columnIdent().name()); | ||
} else { | ||
path.add(0, ident.columnIdent().name()); | ||
} | ||
return new Reference( | ||
new ReferenceInfo( | ||
new ReferenceIdent(ident.tableIdent(), DocSysColumns.DOC.name(), path), | ||
reference.info().granularity(), | ||
reference.valueType() | ||
) | ||
); | ||
} | ||
|
||
private static class PredicateVisitor extends Visitor<Predicate<Reference>> { | ||
@Override | ||
public Symbol visitReference(Reference symbol, Predicate<Reference> predicate) { | ||
if (predicate.apply(symbol)) { | ||
return toSourceLookup(symbol); | ||
} | ||
return symbol; | ||
} | ||
} | ||
|
||
private static class SafeVisitor extends Visitor<TableInfo> { | ||
|
||
@Override | ||
public Symbol visitReference(Reference symbol, TableInfo tableInfo) { | ||
ReferenceIdent ident = symbol.info().ident(); | ||
if (ident.columnIdent().name().startsWith("_")) { | ||
return symbol; | ||
} | ||
String schema = ident.tableIdent().schema(); | ||
if ((schema != null && !schema.equals(DocSchemaInfo.NAME) | ||
|| tableInfo.partitionedByColumns().contains(symbol.info()))) { | ||
return symbol; | ||
} | ||
|
||
return toSourceLookup(symbol); | ||
} | ||
} | ||
|
||
private DocReferenceConverter() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.