Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public PartitionedTableAppender(String tableName, String host, int port, int threadCount) throws java.io.IOException
        public PartitionedTableAppender(string tableName, string host, int port, int threadCount)
        {
            this.tableName = new BasicString(tableName);
            DBConnection   conn = new DBConnection();
            BasicAnyVector locations;
            AbstractVector partitionSchema;
            BasicTable     colDefs;
            BasicIntVector typeInts;

            try
            {
                conn.connect(host, port);
                tableInfo          = (BasicDictionary)conn.run("schema(" + tableName + ")");
                partitionColumnIdx = ((BasicInt)tableInfo.get(new BasicString("partitionColumnIndex"))).Int;
                if (partitionColumnIdx == -1)
                {
                    throw new Exception("Table '" + tableName + "' is not partitioned");
                }
                locations = (BasicAnyVector)tableInfo.get(new BasicString("partitionSites"));
                int partitionType = ((BasicInt)tableInfo.get(new BasicString("partitionType"))).Int;
                partitionSchema       = (AbstractVector)tableInfo.get(new BasicString("partitionSchema"));
                router                = TableRouterFacotry.createRouter(Enum.GetValues(typeof(Entity_PARTITION_TYPE))[partitionType], partitionSchema, locations);
                colDefs               = ((BasicTable)tableInfo.get(new BasicString("colDefs")));
                this.cols             = colDefs.getColumn(0).rows();
                typeInts              = (BasicIntVector)colDefs.getColumn("typeInt");
                this.columnCategories = new Entity_DATA_CATEGORY[this.cols];
                this.columnTypes      = new Entity_DATA_TYPE[this.cols];
                for (int i = 0; i < cols; ++i)
                {
                    this.columnTypes[i]      = Enum.GetValues(typeof(Entity_DATA_TYPE))[typeInts.getInt(i)];
                    this.columnCategories[i] = Entity.typeToCategory(this.columnTypes[i]);
                }
            }
            catch (IOException e)
            {
                throw e;
            }
            finally
            {
                conn.close();
            }

            this.threadCount = threadCount;
            if (this.threadCount <= 0)
            {
                this.threadCount = Math.Min(CORES, locations.rows());
            }
            if (this.threadCount > 0)
            {
                this.threadCount--;
            }
            threadPool = Executors.newFixedThreadPool(this.threadCount);
        }
Пример #2
0
        public void Test_run_return_dict()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            BasicDictionary dict = (BasicDictionary)db.run("dict(1 2 3, 2.3 3.4 5.5)");
            BasicDouble     v    = (BasicDouble)dict.get(new BasicInt(2));

            Assert.AreEqual(3.4, v.getValue());
        }
Пример #3
0
        ///
        /// <param name="tableName"> name of the shared table </param>
        /// <param name="host"> host </param>
        /// <param name="port"> port </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public TableAppender(String tableName, String host, int port) throws java.io.IOException
        public TableAppender(string tableName, string host, int port)
        {
            this.tableName = new BasicString(tableName);
            this.conn      = new DBConnection();
            try
            {
                this.conn.connect(host, port);
                tableInfo = (BasicDictionary)conn.run("schema(" + tableName + ")");
                int partitionColumnIdx = ((BasicInt)tableInfo.get(new BasicString("partitionColumnIndex"))).Int;
                if (partitionColumnIdx != -1)
                {
                    throw new Exception("Table '" + tableName + "' is partitioned");
                }
                BasicTable colDefs = ((BasicTable)tableInfo.get(new BasicString("colDefs")));
                this.cols = colDefs.getColumn(0).rows();
            }
            catch (IOException e)
            {
                throw e;
            }
        }
Пример #4
0
        public autoFitTableAppender(string dbUrl, string tableName, bool asynTask, DBConnection conn)
        {
            this.dbUrl     = dbUrl;
            this.tableName = tableName;
            this.asynTask  = asynTask;
            this.conn      = conn;
            conn.setasynTask(false);
            BasicDictionary tableInfo = (BasicDictionary)conn.run("schema(loadTable(\"" + dbUrl + "\", \"" + tableName + "\"))");
            BasicTable      colDefs;

            colDefs = ((BasicTable)tableInfo.get(new BasicString("colDefs")));
            BasicStringVector names = (BasicStringVector)colDefs.getColumn("name");
            BasicIntVector    types = (BasicIntVector)colDefs.getColumn("typeInt");
            int rows = names.rows();


            this.schema = new Dictionary <string, DATA_TYPE>();
            for (int i = 0; i < rows; ++i)
            {
                schema.Add(names.getString(i), (DATA_TYPE)types.getInt(i));
            }
            conn.setasynTask(asynTask);
        }
        public PartitionedTableAppender(string dbUrl, string tableName, string partitionColName, string appendFunction, IDBConnectionPool pool)
        {
            this.pool    = pool;
            threadCount  = pool.getConnectionCount();
            chunkIndices = new List <List <int> >(threadCount);
            for (int i = 0; i < threadCount; ++i)
            {
                chunkIndices.Add(new List <int>());
            }
            DBConnection   conn = new DBConnection();
            IEntity        partitionSchema;
            BasicTable     colDefs;
            BasicIntVector typeInts;
            int            partitionType;
            DATA_TYPE      partitionColType;

            try
            {
                IDBTask task;
                if (dbUrl == null || dbUrl.Length == 0)
                {
                    task         = new BasicDBTask("schema(" + tableName + ")");
                    appendScript = "tableInsert{" + tableName + "}";
                }
                else
                {
                    task         = new BasicDBTask("schema(loadTable(\"" + dbUrl + "\", \"" + tableName + "\"))");
                    appendScript = "tableInsert{loadTable('" + dbUrl + "', '" + tableName + "')}";
                }
                if (appendFunction != null && appendFunction.Length != 0)
                {
                    appendScript = appendFunction;
                }
                pool.execute(task);
                if (!task.isSuccessful())
                {
                    throw new Exception(task.getErrorMsg());
                }
                tableInfo = (BasicDictionary)task.getResults();

                IEntity partColNames = tableInfo.get(new BasicString("partitionColumnName"));
                if (partColNames == null)
                {
                    throw new Exception("Can't find specified partition column name.");
                }
                if (partColNames.isScalar())
                {
                    if (!((BasicString)partColNames).getString().Equals(partitionColName, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new Exception("Can't find specified partition column name.");
                    }
                    partitionColumnIdx = ((BasicInt)tableInfo.get(new BasicString("partitionColumnIndex"))).getValue();
                    partitionSchema    = tableInfo.get(new BasicString("partitionSchema"));
                    partitionType      = ((BasicInt)tableInfo.get(new BasicString("partitionType"))).getValue();
                    //
                    partitionColType = (DATA_TYPE)((BasicInt)tableInfo.get(new BasicString("partitionColumnType"))).getValue();
                }


                else
                {
                    BasicStringVector vec = (BasicStringVector)partColNames;
                    int dims  = vec.rows();
                    int index = -1;
                    for (int i = 0; i < dims; ++i)
                    {
                        if (!vec.getString(i).Equals(partitionColName, StringComparison.OrdinalIgnoreCase))
                        {
                            index = i;
                            break;
                        }
                    }
                    if (index < 0)
                    {
                        throw new Exception("Can't find specified partition column name.");
                    }
                    partitionColumnIdx = ((BasicIntVector)tableInfo.get(new BasicString("partitionColumnIndex"))).getInt(index);
                    partitionSchema    = ((BasicAnyVector)tableInfo.get(new BasicString("partitionSchema"))).getEntity(index);
                    partitionType      = ((BasicIntVector)tableInfo.get(new BasicString("partitionType"))).getInt(index);
                    //
                    partitionColType = (DATA_TYPE)((BasicIntVector)tableInfo.get(new BasicString("partitionColumnType"))).getInt(index);
                }
                colDefs               = ((BasicTable)tableInfo.get(new BasicString("colDefs")));
                this.cols             = colDefs.getColumn(0).rows();
                typeInts              = (BasicIntVector)colDefs.getColumn("typeInt");
                this.columnCategories = new DATA_CATEGORY[this.cols];
                this.columnTypes      = new DATA_TYPE[this.cols];
                for (int i = 0; i < cols; ++i)
                {
                    this.columnTypes[i]      = (DATA_TYPE)typeInts.getInt(i);
                    this.columnCategories[i] = Utils.typeToCategory(this.columnTypes[i]);
                }
                domain = DomainFactory.createDomain((PARTITION_TYPE)partitionType, partitionColType, partitionSchema);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                conn.close();
            }
        }