@Test public void testRewriteSelectInto() { String sql = "select distinct pm1.g1.e1 into #temp from pm1.g1"; String expected = "INSERT INTO #temp (e1) SELECT DISTINCT pm1.g1.e1 FROM pm1.g1"; helpTestRewriteCommand(sql, expected); }
private Command rewriteSelectInto(Query query) throws TeiidProcessingException{ Into into = query.getInto(); try { List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class); Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList()); insert.setSourceHint(query.getSourceHint()); query.setSourceHint(null); query.setInto(null); insert.setQueryExpression(query); return rewriteInsert(correctDatatypes(insert)); } catch (QueryMetadataException e) { throw new QueryValidatorException(e); } catch (TeiidComponentException e) { throw new QueryValidatorException(e); } }
QueryRewriter { private Command rewriteSelectInto(Query query) throws TeiidProcessingException{ Into into = query.getInto(); try { List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class); Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList()); insert.setSourceHint(query.getSourceHint()); query.setSourceHint(null); query.setInto(null); insert.setQueryExpression(query); return rewriteInsert(correctDatatypes(insert)); } catch (QueryMetadataException e) { throw new QueryValidatorException(e); } catch (TeiidComponentException e) { throw new QueryValidatorException(e); } } }
QueryRewriter { private Command rewriteSelectInto(Query query) throws TeiidProcessingException{ Into into = query.getInto(); try { List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class); Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList()); insert.setSourceHint(query.getSourceHint()); query.setSourceHint(null); query.setInto(null); insert.setQueryExpression(query); return rewriteInsert(correctDatatypes(insert)); } catch (QueryMetadataException e) { throw new QueryValidatorException(e); } catch (TeiidComponentException e) { throw new QueryValidatorException(e); } } private  QueryRewriter(QueryMetadataInterface metadata,
            CommandContext context); }
QueryRewriter { private Command rewriteSelectInto(Query query) throws TeiidProcessingException{ Into into = query.getInto(); try { List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class); Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList()); insert.setSourceHint(query.getSourceHint()); query.setSourceHint(null); query.setInto(null); insert.setQueryExpression(query); return rewriteInsert(correctDatatypes(insert)); } catch (QueryMetadataException e) { throw new QueryValidatorException(e); } catch (TeiidComponentException e) { throw new QueryValidatorException(e); } } private  QueryRewriter(QueryMetadataInterface metadata,
            CommandContext context); static Command evaluateAndRewrite(Command command, Evaluator eval, CommandContext context, QueryMetadataInterface metadata); static Criteria evaluateAndRewrite(Criteria criteria, Evaluator eval, CommandContext context, QueryMetadataInterface metadata); static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context, Map<ElementSymbol, Expression> variableValues); static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context); static boolean isDistinctWithGroupBy(Query query); QueryCommand rewriteOrderBy(QueryCommand queryCommand); static void rewriteOrderBy(QueryCommand queryCommand,
            final OrderBy orderBy, final List projectedSymbols, CommandContext context, QueryMetadataInterface metadata); static Criteria rewriteCriteria(Criteria criteria, CommandContext context, QueryMetadataInterface metadata); static Criteria optimizeCriteria(CompoundCriteria criteria, QueryMetadataInterface metadata); static boolean isNull(Expression expr); static Expression rewriteExpression(Expression expression, CommandContext context, QueryMetadataInterface metadata); static Expression rewriteExpression(Expression expression, CommandContext context, QueryMetadataInterface metadata, boolean rewriteSubcommands); static Command rewriteAsUpsertProcedure(Insert insert, QueryMetadataInterface metadata, CommandContext context); static Query createInlineViewQuery(GroupSymbol inlineGroup,
                                               Command nested,
                                               QueryMetadataInterface metadata,
                                               List<? extends Expression> actualSymbols); static void makeSelectUnique(Select select, boolean expressionSymbolsOnly); static Command createDeleteProcedure(Delete delete, QueryMetadataInterface metadata, CommandContext context); static Command createUpdateProcedure(Update update, QueryMetadataInterface metadata, CommandContext context); }
QueryRewriter { private Command rewriteSelectInto(Query query) throws TeiidProcessingException{ Into into = query.getInto(); try { List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class); Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList()); insert.setSourceHint(query.getSourceHint()); query.setSourceHint(null); query.setInto(null); insert.setQueryExpression(query); return rewriteInsert(correctDatatypes(insert)); } catch (QueryMetadataException e) { throw new QueryValidatorException(e); } catch (TeiidComponentException e) { throw new QueryValidatorException(e); } } private  QueryRewriter(QueryMetadataInterface metadata,
            CommandContext context); static Command evaluateAndRewrite(Command command, Evaluator eval, CommandContext context, QueryMetadataInterface metadata); static Criteria evaluateAndRewrite(Criteria criteria, Evaluator eval, CommandContext context, QueryMetadataInterface metadata); static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context, Map<ElementSymbol, Expression> variableValues); static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context); static boolean isDistinctWithGroupBy(Query query); QueryCommand rewriteOrderBy(QueryCommand queryCommand); static void rewriteOrderBy(QueryCommand queryCommand,
            final OrderBy orderBy, final List projectedSymbols, CommandContext context, QueryMetadataInterface metadata); static Criteria rewriteCriteria(Criteria criteria, CommandContext context, QueryMetadataInterface metadata); static Criteria optimizeCriteria(CompoundCriteria criteria, QueryMetadataInterface metadata); static boolean isNull(Expression expr); static Expression rewriteExpression(Expression expression, CommandContext context, QueryMetadataInterface metadata); static Expression rewriteExpression(Expression expression, CommandContext context, QueryMetadataInterface metadata, boolean rewriteSubcommands); static Command rewriteAsUpsertProcedure(Insert insert, QueryMetadataInterface metadata, CommandContext context); static Query createInlineViewQuery(GroupSymbol inlineGroup,
                                               Command nested,
                                               QueryMetadataInterface metadata,
                                               List<? extends Expression> actualSymbols); static void makeSelectUnique(Select select, boolean expressionSymbolsOnly); static Command createDeleteProcedure(Delete delete, QueryMetadataInterface metadata, CommandContext context); static Command createUpdateProcedure(Update update, QueryMetadataInterface metadata, CommandContext context); static final CompareCriteria TRUE_CRITERIA; static final CompareCriteria FALSE_CRITERIA; static final CompareCriteria UNKNOWN_CRITERIA; }