Esempio n. 1
0
 TempTable getOrCreateTempTable(
     String tempTableID,
     Command command,
     BufferManager buffer,
     boolean delegate,
     boolean forUpdate,
     CommandContext context)
     throws TeiidProcessingException, BlockedException, TeiidComponentException {
   TempTable tempTable = getTempTable(tempTableID, command, buffer, delegate, forUpdate, context);
   if (tempTable != null) {
     if (processors != null) {
       TableProcessor withProcessor = processors.get(tempTableID);
       if (withProcessor != null) {
         buildWithTable(tempTableID, withProcessor, tempTable);
       }
     }
     return tempTable;
   }
   // allow implicit temp group definition
   List<ElementSymbol> columns = null;
   if (command instanceof Insert) {
     Insert insert = (Insert) command;
     GroupSymbol group = insert.getGroup();
     if (group.isImplicitTempGroupSymbol()) {
       columns = insert.getVariables();
     }
   }
   if (columns == null) {
     if (processors != null) {
       TableProcessor withProcessor = processors.get(tempTableID);
       if (withProcessor != null) {
         LogManager.logDetail(
             LogConstants.CTX_DQP,
             "Creating temporary table for with clause",
             tempTableID); //$NON-NLS-1$
         Create create = new Create();
         create.setTable(new GroupSymbol(tempTableID));
         create.setElementSymbolsAsColumns(withProcessor.columns);
         tempTable = addTempTable(tempTableID, create, buffer, true, context);
         buildWithTable(tempTableID, withProcessor, tempTable);
         return tempTable;
       }
     }
     throw new QueryProcessingException(
         QueryPlugin.Event.TEIID30226,
         QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30226, tempTableID));
   }
   LogManager.logDetail(
       LogConstants.CTX_DQP, "Creating temporary table", tempTableID); // $NON-NLS-1$
   Create create = new Create();
   create.setTable(new GroupSymbol(tempTableID));
   create.setElementSymbolsAsColumns(columns);
   return addTempTable(tempTableID, create, buffer, true, context);
 }
 @Test
 public void testTypeAliases() {
   Create create = getFactory().newCreate();
   create.setTable(getFactory().newGroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = getFactory().newElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.STRING.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.BYTE.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c3"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.SHORT.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c4"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.FLOAT.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c5"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.BIG_DECIMAL.getTypeClass());
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   helpTest(
       "Create local TEMPORARY table tempTable (c1 varchar, c2 tinyint, c3 smallint, c4 real, c5 decimal)",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 varchar, c2 tinyint, c3 smallint, c4 real, c5 decimal)",
       create); //$NON-NLS-1$
 }
Esempio n. 3
0
  public static final Create sample2() {
    Create create = new Create();
    create.setTable(new GroupSymbol("temp_table2")); // $NON-NLS-1$

    List elements = new ArrayList();
    elements.add(new ElementSymbol("a")); // $NON-NLS-1$
    elements.add(new ElementSymbol("b")); // $NON-NLS-1$

    create.setElementSymbolsAsColumns(elements);
    return create;
  }
 @Test
 public void testCreateTempTable1() {
   Create create = getFactory().newCreate();
   create.setTable(getFactory().newGroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = getFactory().newElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.BOOLEAN.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.BYTE.getTypeClass());
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   helpTest(
       "Create local TEMPORARY table tempTable (c1 boolean, c2 byte)",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean, c2 byte)",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
Esempio n. 5
0
 @Test
 public void testCreateTempTable2() {
   Create create = new Create();
   create.setTable(new GroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = new ElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
   columns.add(column);
   column = new ElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BYTE);
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   create.getColumns().get(0).setNullType(NullType.No_Nulls);
   helpTest(
       "Create local TEMPORARY table tempTable(c1 boolean not null, c2 byte)",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean NOT NULL, c2 byte)",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
Esempio n. 6
0
 @Test
 public void testCreateTempTable1() {
   Create create = new Create();
   create.setTable(new GroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = new ElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
   columns.add(column);
   column = new ElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BYTE);
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   create.setCommitAction(CommitAction.PRESERVE_ROWS);
   helpTest(
       "Create local TEMPORARY table tempTable (c1 boolean, c2 byte) on commit preserve rows",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean, c2 byte) ON COMMIT PRESERVE ROWS",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
Esempio n. 7
0
 @Test
 public void testCreateTempTableWithPrimaryKey() {
   Create create = new Create();
   create.setTable(new GroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = new ElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
   columns.add(column);
   column = new ElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BYTE);
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   create.getPrimaryKey().add(column);
   helpTest(
       "Create local TEMPORARY table tempTable(c1 boolean, c2 byte, primary key (c2))",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean, c2 byte, PRIMARY KEY(c2))",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
Esempio n. 8
0
 TempTable getOrCreateTempTable(
     String tempTableID,
     Command command,
     BufferManager buffer,
     boolean delegate,
     boolean forUpdate,
     CommandContext context,
     GroupSymbol group)
     throws TeiidProcessingException, BlockedException, TeiidComponentException {
   if (!(group.getMetadataID() instanceof TempMetadataID)) {
     // TODO: use a proper metadata
     TempTableStore tts = context.getSessionTempTableStore();
     context.setDeterminismLevel(Determinism.SESSION_DETERMINISTIC);
     if (tts.getTempTable(tempTableID) == null) {
       // implicitly create global (session scoped) temp table
       LogManager.logDetail(
           LogConstants.CTX_DQP, "binding global temp table to session", group); // $NON-NLS-1$
       QueryMetadataInterface metadata = context.getMetadata();
       Create create = GlobalTableStoreImpl.getCreateCommand(group, false, metadata);
       tts.addTempTable(tempTableID, create, buffer, true, context);
     }
     return getTempTable(tempTableID, command, buffer, delegate, forUpdate, context);
   }
   TempTable tempTable = getTempTable(tempTableID, command, buffer, delegate, forUpdate, context);
   if (tempTable != null) {
     if (processors != null) {
       TableProcessor withProcessor = processors.get(tempTableID);
       if (withProcessor != null) {
         TempTable tt = withProcessor.process(tempTable);
         if (tt != tempTable) {
           return tt;
         }
         processors.remove(tempTableID);
       }
     }
     return tempTable;
   }
   // allow implicit temp group definition
   List<ElementSymbol> columns = null;
   if (command instanceof Insert) {
     Insert insert = (Insert) command;
     if (group.isImplicitTempGroupSymbol()) {
       columns = insert.getVariables();
     }
   }
   if (columns == null) {
     if (processors != null) {
       TableProcessor withProcessor = processors.get(tempTableID);
       if (withProcessor != null) {
         LogManager.logDetail(
             LogConstants.CTX_DQP,
             "Creating temporary table for with clause",
             tempTableID); //$NON-NLS-1$
         Create create = new Create();
         create.setTable(new GroupSymbol(tempTableID));
         create.setElementSymbolsAsColumns(withProcessor.columns);
         withProcessor.alterCreate(create);
         tempTable = addTempTable(tempTableID, create, buffer, true, context);
         TempTable tt = withProcessor.process(tempTable);
         if (tt != tempTable) {
           return tt;
         }
         processors.remove(tempTableID);
         return tempTable;
       }
     }
     if (delegate && this.parentTempTableStore != null) {
       // may be a cte from a higher scope that needs to have creation triggered
       return parentTempTableStore.getOrCreateTempTable(
           tempTableID, command, buffer, delegate, forUpdate, context, group);
     }
     throw new QueryProcessingException(
         QueryPlugin.Event.TEIID30226,
         QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30226, tempTableID));
   }
   LogManager.logDetail(
       LogConstants.CTX_DQP, "Creating temporary table", tempTableID); // $NON-NLS-1$
   Create create = new Create();
   create.setTable(new GroupSymbol(tempTableID));
   create.setElementSymbolsAsColumns(columns);
   return addTempTable(tempTableID, create, buffer, true, context);
 }