def test_invalid_argument_type(self):
        keyspace = 'keyspace1'
        column_family = 'cf1'

        column_metadata = [(keyspace, column_family, 'foo1', Int32Type),
                           (keyspace, column_family, 'foo2', Int32Type)]

        prepared_statement = PreparedStatement(column_metadata=column_metadata,
                                               query_id=None,
                                               routing_key_indexes=[],
                                               query=None,
                                               keyspace=keyspace)
        bound_statement = BoundStatement(prepared_statement=prepared_statement)

        values = ['nonint', 1]

        try:
            bound_statement.bind(values)
        except TypeError as e:
            self.assertIn('foo1', str(e))
            self.assertIn('Int32Type', str(e))
            self.assertIn('str', str(e))
        else:
            self.fail('Passed invalid type but exception was not thrown')

        values = [1, ['1', '2']]

        try:
            bound_statement.bind(values)
        except TypeError as e:
            self.assertIn('foo2', str(e))
            self.assertIn('Int32Type', str(e))
            self.assertIn('list', str(e))
        else:
            self.fail('Passed invalid type but exception was not thrown')
Пример #2
0
  def start_fetching_events_async(self, start_id, end_id):
    if self.descending:
      select_stmt = self.namespace.SELECT_DESC_STMT
    else:
      select_stmt = self.namespace.SELECT_ASC_STMT

    select_stmt = BoundStatement(select_stmt,
                                 fetch_size=self.read_size or 5000,
                                 routing_key=self.key,
                                 consistency_level=ConsistencyLevel.ONE)
    self._events_future = self.session.execute_async(
      select_stmt.bind((self.key, start_id, end_id, self.limit)))
Пример #3
0
 def ids_iterator(self, start_id, end_id):
   select_ids_stmt = BoundStatement(self.namespace.SELECT_ID_STMT,
                                    fetch_size=100000,  # 100k ids at a time.
                                    routing_key=self.key,
                                    consistency_level=ConsistencyLevel.ONE)
   ids = self.session.execute(
     select_ids_stmt.bind((self.key, start_id, end_id, self.limit)))
   for _id in ids:
     try:
       yield _id[0]
     except GeneratorExit:
       break
    def test_invalid_argument_type(self):
        keyspace = 'keyspace1'
        column_family = 'cf1'

        column_metadata = [
            (keyspace, column_family, 'foo1', Int32Type),
            (keyspace, column_family, 'foo2', Int32Type)
        ]

        prepared_statement = PreparedStatement(column_metadata=column_metadata,
                                               query_id=None,
                                               routing_key_indexes=[],
                                               query=None,
                                               keyspace=keyspace,
                                               protocol_version=2)
        bound_statement = BoundStatement(prepared_statement=prepared_statement)

        values = ['nonint', 1]

        try:
            bound_statement.bind(values)
        except TypeError as e:
            self.assertIn('foo1', str(e))
            self.assertIn('Int32Type', str(e))
            self.assertIn('str', str(e))
        else:
            self.fail('Passed invalid type but exception was not thrown')

        values = [1, ['1', '2']]

        try:
            bound_statement.bind(values)
        except TypeError as e:
            self.assertIn('foo2', str(e))
            self.assertIn('Int32Type', str(e))
            self.assertIn('list', str(e))
        else:
            self.fail('Passed invalid type but exception was not thrown')
Пример #5
0
 def get_overlapping_shards(self, start_time, end_time):
   index_scan_stmt = BoundStatement(self.namespace.INDEX_SCAN_STMT)
   potential_shards = self.session.execute(
     index_scan_stmt.bind((self.stream,
                           max(start_time - Stream.MAX_WIDTH, 0),
                           end_time))
   )
   shards = defaultdict(lambda: defaultdict(int))
   for (shard_time, width, shard) in potential_shards:
     if shard_time + width < start_time:
       # end_time < shard start_time?
       continue
     shards[shard_time][shard] = max(shards[shard_time][shard], width)
   for shard_time, _ in shards.iteritems():
     for shard, width in _.iteritems():
       yield {'start_time': shard_time,
              'width': width,
              'shard': shard}
    def test_invalid_argument_type(self):
        keyspace = 'keyspace1'
        column_family = 'cf1'

        column_metadata = [
            (keyspace, column_family, 'foo1', Int32Type),
            (keyspace, column_family, 'foo2', Int32Type)
        ]

        prepared_statement = PreparedStatement(column_metadata=column_metadata,
                                               query_id=None,
                                               routing_key_indexes=[],
                                               query=None,
                                               keyspace=keyspace)
        bound_statement = BoundStatement(prepared_statement=prepared_statement)

        values = ['nonint', 1]

        try:
            bound_statement.bind(values)
        except InvalidParameterTypeError as e:
            self.assertEqual(e.col_name, 'foo1')
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, str)
        else:
            self.fail('Passed invalid type but exception was not thrown')

        try:
            bound_statement.bind(values)
        except TypeError as e:
            self.assertEqual(e.col_name, 'foo1')
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, str)
        else:
            self.fail('Passed invalid type but exception was not thrown')

        values = [1, ['1', '2']]

        try:
            bound_statement.bind(values)
        except InvalidParameterTypeError as e:
            self.assertEqual(e.col_name, 'foo2')
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, list)
        else:
            self.fail('Passed invalid type but exception was not thrown')
    def test_invalid_argument_type(self):
        keyspace = 'keyspace1'
        column_family = 'cf1'

        column_metadata = [(keyspace, column_family, 'foo1', Int32Type),
                           (keyspace, column_family, 'foo2', Int32Type)]

        prepared_statement = PreparedStatement(column_metadata=column_metadata,
                                               query_id=None,
                                               routing_key_indexes=[],
                                               query=None,
                                               keyspace=keyspace)
        bound_statement = BoundStatement(prepared_statement=prepared_statement)

        values = ['nonint', 1]

        try:
            bound_statement.bind(values)
        except InvalidParameterTypeError as e:
            self.assertEqual(e.col_name, 'foo1')
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, str)
        else:
            self.fail('Passed invalid type but exception was not thrown')

        try:
            bound_statement.bind(values)
        except TypeError as e:
            self.assertEqual(e.col_name, 'foo1')
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, str)
        else:
            self.fail('Passed invalid type but exception was not thrown')

        values = [1, ['1', '2']]

        try:
            bound_statement.bind(values)
        except InvalidParameterTypeError as e:
            self.assertEqual(e.col_name, 'foo2')
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, list)
        else:
            self.fail('Passed invalid type but exception was not thrown')
    def test_invalid_argument_type(self):
        keyspace = "keyspace1"
        column_family = "cf1"

        column_metadata = [(keyspace, column_family, "foo1", Int32Type), (keyspace, column_family, "foo2", Int32Type)]

        prepared_statement = PreparedStatement(
            column_metadata=column_metadata, query_id=None, routing_key_indexes=[], query=None, keyspace=keyspace
        )
        bound_statement = BoundStatement(prepared_statement=prepared_statement)

        values = ["nonint", 1]

        try:
            bound_statement.bind(values)
        except InvalidParameterTypeError as e:
            self.assertEqual(e.col_name, "foo1")
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, str)
        else:
            self.fail("Passed invalid type but exception was not thrown")

        try:
            bound_statement.bind(values)
        except TypeError as e:
            self.assertEqual(e.col_name, "foo1")
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, str)
        else:
            self.fail("Passed invalid type but exception was not thrown")

        values = [1, ["1", "2"]]

        try:
            bound_statement.bind(values)
        except InvalidParameterTypeError as e:
            self.assertEqual(e.col_name, "foo2")
            self.assertEqual(e.expected_type, Int32Type)
            self.assertEqual(e.actual_type, list)
        else:
            self.fail("Passed invalid type but exception was not thrown")