private static Pair<SqlNode, RelDataType> validateNode(SqlHandlerConfig config, final SqlNode sqlNode) throws ValidationException, RelConversionException, ForemanSetupException { final Stopwatch stopwatch = Stopwatch.createStarted(); final SqlNode sqlNodeValidated; try { sqlNodeValidated = config.getConverter().validate(sqlNode); } catch (final Throwable ex) { throw new ValidationException("unable to validate sql node", ex); } final Pair<SqlNode, RelDataType> typedSqlNode = new Pair<>(sqlNodeValidated, config.getConverter().getOutputType(sqlNodeValidated)); // Check if the unsupported functionality is used UnsupportedOperatorsVisitor visitor = UnsupportedOperatorsVisitor.createVisitor(config.getContext()); try { sqlNodeValidated.accept(visitor); } catch (UnsupportedOperationException ex) { // If the exception due to the unsupported functionalities visitor.convertException(); // If it is not, let this exception move forward to higher logic throw ex; } config.getObserver().planValidated(typedSqlNode.getValue(), typedSqlNode.getKey(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); return typedSqlNode; }
public static RelRoot expandView(NamespaceKey path, final String viewOwner, final String queryString, final List<String> context, final SqlConverter sqlConverter) { ViewExpansionToken token = null; try { //RelDataType rowType = view.getRowType(cluster.getTypeFactory()); token = sqlConverter.getViewExpansionContext().reserveViewExpansionToken(viewOwner); final DremioCatalogReader catalog; if(viewOwner != null) { catalog = sqlConverter.getCatalogReader().withSchemaPathAndUser(viewOwner, context); } else { catalog = sqlConverter.getCatalogReader().withSchemaPath(context); } final SqlConverter newConverter = new SqlConverter(sqlConverter, catalog); final SqlNode parsedNode = newConverter.parse(queryString); final SqlNode validatedNode = newConverter.validate(parsedNode); final RelRootPlus root = newConverter.toConvertibleRelRoot(validatedNode, true); if(path == null) { return root; } // we need to make sure that if a inner expansion is context sensitive, we consider the current // expansion context sensitive even if it isn't locally. final boolean contextSensitive = root.isContextSensitive() || ExpansionNode.isContextSensitive(root.rel); return new RelRoot(ExpansionNode.wrap(path, root.rel, contextSensitive), root.validatedRowType, root.kind, root.fields, root.collation); } finally { if (token != null) { token.release(); } } }