当前位置: 首页>>代码示例>>Python>>正文


Python columnfamily.ColumnFamily类代码示例

本文整理汇总了Python中pycassa.columnfamily.ColumnFamily的典型用法代码示例。如果您正苦于以下问题:Python ColumnFamily类的具体用法?Python ColumnFamily怎么用?Python ColumnFamily使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ColumnFamily类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_row_key_id

def get_row_key_id(domain):
    counter_column, counter_lock = domain_counter_map[domain]
    
    ## acquire lock before getting value of 
    counter_lock.acquire()
    try:
        client = db_connection.get_client()
        cf = ColumnFamily(client, CONFIG_DOMAIN)
        
        ## get new key id
        id_key = cf.get(CONFIG_ROW, counter_column)[counter_column]
        
        ## increment value if not None
        if id_key:
            new_id_key = id_key + 1
            cf.insert(CONFIG_ROW, {counter_column: new_id_key}, write_consistency_level=ConsistencyLevel.ALL)
        
        return id_key
        
        """
        if id_key:
            str_id_key = str(id_key)
            str_id_key.zfill(MAX_PADDING_RANGE)
            return str_id_key
        else:
            return None
        """
        
    finally:
        ## release lock before returning from this function
        counter_lock.release()
开发者ID:asorici,项目名称:envsmth,代码行数:31,代码来源:utils.py

示例2: __init__

 def __init__(self,keySpace):
     self.pool = ConnectionPool(keySpace, ['localhost:9160'])
     self.col_fam_page        = ColumnFamily(self.pool, 'Page')
     self.col_fam_publication = ColumnFamily(self.pool, 'Publication')
     self.col_fam_company     = ColumnFamily(self.pool, 'Company')
     self.col_fam_location    = ColumnFamily(self.pool, 'Location')
     self.col_fam_category    = ColumnFamily(self.pool, 'Category')
开发者ID:megajandro,项目名称:py-blw,代码行数:7,代码来源:clientCassandra.py

示例3: __init__

    def __init__(self, client, qname, trend=5):
        super(Buyer, self).__init__(client, uuid.uuid4().hex)
        self.holdings = {}
        self.cash = 100000.0
        self.history = {}
        self.trend = trend
        self.pool = ConnectionPool('example_consumer_Buyer')
        self.stored_holdings = ColumnFamily(self.pool, 'Holdings')
        self.quote_history = ColumnFamily(self.pool, 'Quotes')
        self.stored_cash = ColumnFamily(self.pool, 'Cash')

        try:
          cash = self.stored_cash.get('current')
          self.cash = cash['amount']
        except ttypes.NotFoundException:
          self.stored_cash.insert('current', { 'amount': self.cash })

        for symbol, columns in self.stored_holdings.get_range():
          self.holdings[symbol] = (columns['number_of_shares'], columns['price'], columns['cost'])

        date_expression = create_index_expression('timestamp', datetime.date.today(), GT)
        date_clause = create_index_clause([date_expression], count=1000)

        for key, columns in self.quote_history.get_range():
          symbol = columns['symbol']
          price = columns['price']
          self.add_quote(symbol, price)
开发者ID:simonwgill,项目名称:octo-llama,代码行数:27,代码来源:buy_low_sell_high.py

示例4: datatable

def datatable():

    session = cassandra.connect()
    session.set_keyspace(settings['cluster_name'])
    cass_client = ConnectionPool(settings['cluster_name'],[settings['cass_cluster']+':'+settings['thrift_port']], timeout=60)
    col_fam = ColumnFamily(cass_client,'parsed_data')
    session.default_timeout = 100
    key1 = request.args.get('key')
    if key1 == None:
        key1=100
    key1= int(key1)
    query = "SELECT last_timeid FROM main_count"  # users contains 100 rows
    statement = session.execute(query)
    for x in statement:
        end_key = x[0]
    log_data = [[]for i in range(0,key1)]
    log_data_header,k = [], 0
    temp = end_key-key1
    for i in range(temp,end_key):
        expr2 = create_index_expression('logid',i)
        lause = create_index_clause([ expr2], count=1)
        test = list(col_fam.get_indexed_slices(lause, columns= ["timestamp", "host", "byte_transfer", "request_link", "request_details", "device_type", "operating_system", "request_type", "response_code", "response_time"]))[0][1]
        for m in test.values():
            log_data[k].append(m)
        k += 1
        if k == 1:
            for n in test.keys():
                log_data_header.append(n)
    return render_template('datatable.html', data= log_data, data_header = log_data_header,index = key1)
开发者ID:asinha093,项目名称:LogAnalysis,代码行数:29,代码来源:dashboard.py

示例5: CassandraRepository

class CassandraRepository(object):
    def __init__(self, keyspace, column_family_name):
        self.pool = ConnectionPool(keyspace,
                                   cassandra_settings.NODE_POOL)

        self.cf = ColumnFamily(self.pool, column_family_name)

        self.batch = {}

    def add_batch(self, batch, start_time=None):
        """
        :param batch:
        """

        self.cf.batch_insert(batch)
        if start_time is not None:
            print 'time to  insert batch: %s ms' % (int(time.time() * 1000) - start_time)


    def get(self, timestamp):
        return self.cf.get(str(timestamp))

    def get_range(self, start, end):
        return list(self.cf.get_range(start=str(start), finish=str(end)))

    def close(self):
        self.sys.close()
开发者ID:lsptb,项目名称:live-visualization,代码行数:27,代码来源:cassandra_repository.py

示例6: get

def get():
#################### TEMP
  #userId = 'user-784b9158-5233-454e-8dcf-c229cdff12c6'
  print 'Getting result for userId: {0} between time {1} and {2}'.format(userId, startTime, startTime)
  con = util.getConnection()
  logCF = ColumnFamily(con, 'event_log_mux')
  
  rowKeys = ['{0}:{1}'.format(userId, i+1) for i in range(4)]
  rows = logCF.multiget(rowKeys)
  
  print 'Shows rows multiplexes into different rows each individually sorted in reverse cronological order:'
  merge = {}
  for row in rows:
    print '>> '+str(row) 
    merge = dict(merge.items() + rows[row].items())
    for col in rows[row]:
      colstr = rows[row][col]
      coljson = json.loads(colstr)
      print '\tInsertion Timestamp: {0}'.format(coljson['insert_time'])
  
  final = collections.OrderedDict(sorted(merge.items(), reverse=True))
  for k,v in final.iteritems():
    coljson = json.loads(v)
    print 'insertion timestamp: {0}'.format(coljson['insert_time'])

  """
开发者ID:djnesmith,项目名称:mastering_cassandra,代码行数:26,代码来源:ch3_2.3.2_time_series2.py

示例7: __init__

    def __init__(self):
	err = ''
        self.pool = ConnectionPool('jobrun', server_list=options['hosts'])
        self.jl = ColumnFamily(self.pool, 'job_lookup')
        self.jr = ColumnFamily(self.pool, 'job_results')
        self.jd = ColumnFamily(self.pool, 'job_dashboard')
        self.jf = ColumnFamily(self.pool, 'job_failures')
开发者ID:jobrun,项目名称:jobrun,代码行数:7,代码来源:jobrun2.py

示例8: colum_family_content

 def colum_family_content(self, keyspace_name, column_family_name):
     """Returns content of column family of given keyspace """
     keyspace.cf_result = []
     keyspace.error = "Unknown error : May be one of node in your cluster is down please check?"
     if not self.keyspace_contains(keyspace.local_system, keyspace_name, column_family_name):
         keyspace.error = "Desired Keyspace,Column Family pair could not be found."
         return False
     try:
         pool = ConnectionPool(keyspace=keyspace_name, server_list=keyspace.server_ips, prefill=False)
     except Exception as e:
         print e
         return False
     try:
         col_fam = ColumnFamily(pool, column_family_name)
     except Exception as e:
         print e
         return False
     result = []
     try:
         tmp_result = col_fam.get_range(start='', finish='', buffer_size=10)
         for i in tmp_result:
             result.append(i)
     except Exception as e:
         print e
         return False
     keyspace.cf_result = result
     keyspace.tempks = keyspace_name
     keyspace.tempcf = column_family_name
     print result
     return result
开发者ID:neel1438,项目名称:Cassandra-BigDataEditor,代码行数:30,代码来源:app.py

示例9: colum_family_content

	def colum_family_content(self,machine_id,keyspace_name,column_family_name):
		"""Returns content of column family of given keyspace """
		print "->>>in column family content function"
		pool = ConnectionPool(keyspace_name, [machine_id])
		col_fam = ColumnFamily(pool, column_family_name)
		result = col_fam.get_range(start='', finish='')
		return result
开发者ID:borntorock,项目名称:CassandraBrowserTool,代码行数:7,代码来源:backend_code.py

示例10: __init__

    def __init__(self, cls, pool, column_family, columns=None, raw_columns=False, **kwargs):
        """
        Maps an existing class to a column family.  Class fields become columns,
        and instances of that class can be represented as rows in standard column
        families or super columns in super column families.

        Instances of `cls` are returned from :meth:`get()`, :meth:`multiget()`,
        :meth:`get_range()` and :meth:`get_indexed_slices()`.
        
        `pool` is a :class:`~pycassa.pool.ConnectionPool` that will be used
        in the same way a :class:ColumnFamily uses one.

        `column_family` is the name of a column family to tie to `cls`.

        If `raw_columns` is ``True``, all columns will be fetched into the
        `raw_columns` field in requests.

        """
        ColumnFamily.__init__(self, pool, column_family, **kwargs)

        self.cls = cls
        self.autopack_names = False

        self.raw_columns = raw_columns
        self.dict_class = util.OrderedDict
        self.defaults = {}
        self.fields = []
        for name, val_type in self.cls.__dict__.iteritems():
            if isinstance(val_type, CassandraType):
                self.fields.append(name)
                self.column_validators[name] = val_type
                self.defaults[name] = val_type.default
开发者ID:gustavopinto,项目名称:pycassa,代码行数:32,代码来源:columnfamilymap.py

示例11: load_slaves

    def load_slaves(self, o):
        cf = ColumnFamily(self._pool, 'slaves')
        with cf.batch() as batch:
            for slave_id, name in o.items():
                batch.insert(slave_id, {'name': name})

        return len(o)
开发者ID:staktrace,项目名称:mozilla-build-analyzer,代码行数:7,代码来源:buildbotdata.py

示例12: get_builder

 def get_builder(self, builder_id):
     """Obtain info about a builder from its ID."""
     cf = ColumnFamily(self.pool, 'builders')
     try:
         return cf.get(builder_id)
     except NotFoundException:
         return None
开发者ID:AutomatedTester,项目名称:mozilla-build-analyzer,代码行数:7,代码来源:cassandra.py

示例13: loadData

def loadData():
  con = util.getConnection()
  cf = ColumnFamily(con, 'videos_denorm')
  tagCF = ColumnFamily(con, 'tag_videos_composite')
  movies = util.readCSV('data/movies')
  for movie in movies:
    title = movie[0]
    uploader = movie[1]
    runtime = int(movie[2]) #convert to match column validator
    tags = movie[3]
    rowKey = title+":"+uploader


    print "Inserting in videos: {}.".format(str(movie))
    row = \
      {
        'title':title,
        'user_name':uploader,
        'runtime_in_sec':runtime,
      }

    for tag in tags.split(','):
      print 'adding tag: {0} for movie: {1}'.format(tag, title)
      row['tag:{}'.format(tag.strip().lower())] = tag.strip()

    print 'inserting denorm: {}'.format(row)
    cf.insert(rowKey, row)

  print 'finishished insertion.'    
  con.dispose()
开发者ID:djnesmith,项目名称:mastering_cassandra,代码行数:30,代码来源:ch3_2.1_tag_management1.py

示例14: get_reverse

def get_reverse(columnFamily, key) :
        "select values in a given column family"
        try :
	        column = ColumnFamily(pool, columnFamily)
	        return column.get(key,column_reversed=True)
	except:
		return {'status':0}
开发者ID:redjohn19,项目名称:CloudMajor,代码行数:7,代码来源:operations.py

示例15: remove_column

def remove_column(columnFamily, uid, columns) :
	"To remove columns from a key"
	try:
		column = ColumnFamily(pool, columnFamily)
		column.remove(uid,columns)
	except:
		return {'status':0}
开发者ID:redjohn19,项目名称:CloudMajor,代码行数:7,代码来源:operations.py


注:本文中的pycassa.columnfamily.ColumnFamily类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。