Package com.foundationdb.qp.operator

Examples of com.foundationdb.qp.operator.StoreAdapter


                }
                break;
            case TABLE:
                if(transform.deleteOperator != null && transform.insertOperator != null) {
                    Schema schema = transform.rowType.schema();
                    StoreAdapter adapter = store.createAdapter(session, schema);
                    context = new SimpleQueryContext(adapter);
                    QueryBindings bindings = context.createBindings();
                    if (doDelete) {
                        Row origOldRow = new RowDataRow(transform.rowType, oldRowData);
                        bindings.setRow(OperatorAssembler.CREATE_AS_BINDING_POSITION, origOldRow);
                        try {
                            runPlan(context, transform.deleteOperator, bindings);
                        } catch (NoSuchRowException e) {
                            LOG.debug("row not present: {}", origOldRow);
                        }
                    }
                    if (doWrite) {
                        Row origOldRow = new RowDataRow(transform.rowType, newRowData);
                        bindings.setRow(OperatorAssembler.CREATE_AS_BINDING_POSITION, origOldRow);
                        try {
                            runPlan(context, transform.insertOperator, bindings);
                        } catch (NoSuchRowException e) {
                            LOG.debug("row not present: {}", origOldRow);
                        }
                    }
                    break;
                }
            case GROUP:
                Schema schema = transform.rowType.schema();
                StoreAdapter adapter = store.createAdapter(session, schema);
                context = new SimpleQueryContext(adapter);
                QueryBindings bindings = context.createBindings();
                if(doDelete) {
                    Row origOldRow = new RowDataRow(transform.rowType, oldRowData);
                    Row newOldRow = transformRow(context, bindings, transform, origOldRow);
                    try {
                        adapter.deleteRow(newOldRow, false);
                    } catch(NoSuchRowException e) {
                        LOG.debug("row not present: {}", newOldRow);
                    }
                }
                if(doWrite) {
                    Row origNewRow = new RowDataRow(transform.rowType, newRowData);
                    Row newNewRow = transformRow(context, bindings, transform, origNewRow);
                    adapter.writeRow(newNewRow, transform.tableIndexes, transform.groupIndexes);
                }
                break;
        }
        transform.hKeySaver.save(schemaManager, session, hKey);
    }
View Full Code Here


                try {
                    insertStmt = parser.parseStatement("insert into " + newAIS.getTable(cs.getToTableId()).getName().toStringEscaped() + " " + cs.getSelectStatement());
                } catch (StandardException e) {
                    throw new SQLParserInternalException(e);
                }
                StoreAdapter adapter = givenStore.createAdapter(session, SchemaCache.globalSchema(newAIS));
                CreateAsCompiler compiler = new CreateAsCompiler(server, adapter, true, newAIS);
                PlanContext planContext = new PlanContext(compiler);
                BasePlannable insertResult = compiler.compile((DMLStatementNode) insertStmt, null, planContext);
                insertPlan = insertResult.getPlannable();
                deletePlan = new Delete_Returning(insertPlan.getInputOperators().iterator().next(), false);
View Full Code Here

        AkibanInformationSchema ais = ais();
        Table table = ais.getTable(tid);
        List<Column> columns = Collections.singletonList(table.getColumn("name"));
        InputStream istr = new ByteArrayInputStream(CSV.getBytes("UTF-8"));
        Schema schema = SchemaCache.globalSchema(ais);
        StoreAdapter adapter = newStoreAdapter(schema);
        QueryContext queryContext = new SimpleQueryContext(adapter) {
                @Override
                public ServiceManager getServiceManager() {
                    return serviceManager();
                }
                @Override
                public String getCurrentSchema() {
                    return SCHEMA;
                }
            };
        long nrows = external.loadTableFromCsv(session(), istr, new CsvFormat("UTF-8"),
                                               0, table, columns,
                                               -1, 1, queryContext);
        assertEquals(4, nrows);
        RowType rowType = schema.tableRowType(table);
        compareRows(new Row[] {
                        testRow(rowType, 1L, "Fred", SCHEMA),
                        testRow(rowType, 2L, "Wilma", SCHEMA),
                        testRow(rowType, 3L, "Barney", SCHEMA),
                        testRow(rowType, 4L, "Betty", SCHEMA)
                    },
                    adapter.newGroupCursor(table.getGroup()));
    }
View Full Code Here

    private void runPlan(String expectedSQL) throws Exception {
        DumpGroupLoadablePlan loadablePlan = new DumpGroupLoadablePlan();
        DirectObjectPlan plan = loadablePlan.plan();

        Schema schema = new Schema(ais());
        StoreAdapter adapter = newStoreAdapter(schema);
        QueryContext queryContext = new SimpleQueryContext(adapter) {
                @Override
                public String getCurrentSchema() {
                    return SCHEMA_NAME;
                }
View Full Code Here

        assertEquals(Collections.singletonList(MessageFormat.format(ErrorCode.NO_SUCH_SEQUENCE.getMessage(), "test", "not_exists")), getWarnings());
    }

    @Test
    public void durableAfterRollbackAndRestart() throws Exception {
        StoreAdapter adapter = newStoreAdapter(SchemaCache.globalSchema(ddl().getAIS(session())));
        TableName seqName = new TableName("test", "s1");
        String sql = "CREATE SEQUENCE "+seqName+" START WITH 1 INCREMENT BY 1";
        executeDDL(sql);
        Sequence s1 = ais().getSequence(seqName);
        assertNotNull("s1", s1);

        txnService().beginTransaction(session());
        assertEquals("start val a", 0, adapter.sequenceCurrentValue(s1));
        assertEquals("next val a", 1, adapter.sequenceNextValue(s1));
        txnService().commitTransaction(session());

        txnService().beginTransaction(session());
        assertEquals("next val b", 2, adapter.sequenceNextValue(s1));
        assertEquals("cur val b", 2, adapter.sequenceCurrentValue(s1));
        txnService().rollbackTransactionIfOpen(session());

        txnService().beginTransaction(session());
        // Expected gap, see nextValue() impl
        assertEquals("next val c", 3, adapter.sequenceNextValue(s1));
        txnService().commitTransaction(session());

        safeRestartTestServices();
        adapter = newStoreAdapter(SchemaCache.globalSchema(ddl().getAIS(session())));

        s1 = ais().getSequence(seqName);
        txnService().beginTransaction(session());
        long nextVal = adapter.sequenceNextValue(s1);
        if(nextVal <= 3) {
            fail("Expected val > 3: " + nextVal);
        }
        txnService().commitTransaction(session());
        dropSequence(seqName);
View Full Code Here

        dropSequence(seqName);
    }

    @Test
    public void freshValueAfterDropAndRecreate() throws Exception {
        StoreAdapter adapter = newStoreAdapter(SchemaCache.globalSchema(ddl().getAIS(session())));
        final TableName seqName = new TableName("test", "s2");
        final String create = "CREATE SEQUENCE "+seqName+" START WITH 1 INCREMENT BY 1";
        final String drop = "DROP SEQUENCE "+seqName+" RESTRICT";
        for(int i = 1; i <= 2; ++i) {
            executeDDL(create);
            Sequence s1 = ais().getSequence(seqName);
            assertNotNull("s1, loop"+i, s1);

            txnService().beginTransaction(session());
            assertEquals("start val, loop"+i, 0, adapter.sequenceCurrentValue(s1));
            assertEquals("next val, loop"+i, 1, adapter.sequenceNextValue(s1));
            txnService().commitTransaction(session());

            executeDDL(drop);
        }
    }
View Full Code Here

        assertEquals("max", Integer.MAX_VALUE, s.getMaxValue());
    }

    @Test
    public void wrapCacheSize() throws Exception {
        StoreAdapter adapter = newStoreAdapter(SchemaCache.globalSchema(ddl().getAIS(session())));
        final TableName seqName = new TableName ("test", "s5");
        final String create = "CREATE SEQUENCE "+seqName+" START WITH 1 INCREMENT BY 1";
        executeDDL(create);
        Sequence s1 = ais().getSequence(seqName);
        for (int i = 1; i <= 103; ++i) {
            txnService().beginTransaction(session());
            assertEquals("loop cache size match", i, adapter.sequenceNextValue(s1));
            txnService().commitTransaction(session());
        }
        dropSequence(seqName);
    }
View Full Code Here

    public void invokePersistitOperation() throws Exception {
        PersistitCLILoadablePlan loadablePlan = new PersistitCLILoadablePlan();
        DirectObjectPlan plan = loadablePlan.plan();

        Schema schema = new Schema(ais());
        StoreAdapter adapter = newStoreAdapter(schema);
        QueryContext queryContext = queryContext(adapter);
        QueryBindings queryBindings = queryContext.createBindings();

        DirectObjectCursor cursor = plan.cursor(queryContext, queryBindings);
        queryBindings.setValue(0, new Value(MString.varcharFor("stat"), "stat"));
View Full Code Here

TOP

Related Classes of com.foundationdb.qp.operator.StoreAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.