35
35
import os
36
36
import re
37
37
import sys
38
+ import warnings
38
39
39
40
from . import environment
40
41
@@ -505,8 +506,8 @@ def __init__(self, ofile, maxresultrows=None):
505
506
506
507
self ._inspector = OrderedDict ()
507
508
self ._chunk_count = 0
508
- self ._record_count = 0
509
- self ._total_record_count = 0
509
+ self ._pending_record_count = 0
510
+ self ._committed_record_count = 0
510
511
511
512
@property
512
513
def is_flushed (self ):
@@ -524,6 +525,30 @@ def ofile(self):
524
525
def ofile (self , value ):
525
526
self ._ofile = set_binary_mode (value )
526
527
528
+ @property
529
+ def pending_record_count (self ):
530
+ return self ._pending_record_count
531
+
532
+ @property
533
+ def _record_count (self ):
534
+ warnings .warn (
535
+ "_record_count will be deprecated soon. Use pending_record_count instead." ,
536
+ PendingDeprecationWarning
537
+ )
538
+ return self .pending_record_count
539
+
540
+ @property
541
+ def committed_record_count (self ):
542
+ return self ._committed_record_count
543
+
544
+ @property
545
+ def _total_record_count (self ):
546
+ warnings .warn (
547
+ "_total_record_count will be deprecated soon. Use committed_record_count instead." ,
548
+ PendingDeprecationWarning
549
+ )
550
+ return self .committed_record_count
551
+
527
552
def write (self , data ):
528
553
bytes_type = bytes if sys .version_info >= (3 , 0 ) else str
529
554
if not isinstance (data , bytes_type ):
@@ -555,7 +580,7 @@ def _clear(self):
555
580
self ._buffer .seek (0 )
556
581
self ._buffer .truncate ()
557
582
self ._inspector .clear ()
558
- self ._record_count = 0
583
+ self ._pending_record_count = 0
559
584
560
585
def _ensure_validity (self ):
561
586
if self ._finished is True :
@@ -650,9 +675,9 @@ def _write_record(self, record):
650
675
values += (repr (value ), None )
651
676
652
677
self ._writerow (values )
653
- self ._record_count += 1
678
+ self ._pending_record_count += 1
654
679
655
- if self ._record_count >= self ._maxresultrows :
680
+ if self .pending_record_count >= self ._maxresultrows :
656
681
self .flush (partial = True )
657
682
658
683
try :
@@ -689,7 +714,7 @@ def flush(self, finished=None, partial=None):
689
714
690
715
RecordWriter .flush (self , finished , partial ) # validates arguments and the state of this instance
691
716
692
- if self ._record_count > 0 or (self ._chunk_count == 0 and 'messages' in self ._inspector ):
717
+ if self .pending_record_count > 0 or (self ._chunk_count == 0 and 'messages' in self ._inspector ):
693
718
694
719
messages = self ._inspector .get ('messages' )
695
720
@@ -727,9 +752,9 @@ def flush(self, finished=None, partial=None):
727
752
print (level , text , file = stderr )
728
753
729
754
self .write (self ._buffer .getvalue ())
730
- self ._clear ()
731
755
self ._chunk_count += 1
732
- self ._total_record_count += self ._record_count
756
+ self ._committed_record_count += self .pending_record_count
757
+ self ._clear ()
733
758
734
759
self ._finished = finished is True
735
760
@@ -758,25 +783,22 @@ def flush(self, finished=None, partial=None):
758
783
759
784
def write_chunk (self , finished = None ):
760
785
inspector = self ._inspector
761
- self ._total_record_count += self ._record_count
786
+ self ._committed_record_count += self .pending_record_count
762
787
self ._chunk_count += 1
763
788
764
789
# TODO: DVPL-6448: splunklib.searchcommands | Add support for partial: true when it is implemented in
765
790
# ChunkedExternProcessor (See SPL-103525)
766
791
#
767
792
# We will need to replace the following block of code with this block:
768
793
#
769
- # metadata = [
770
- # ('inspector', self._inspector if len(self._inspector) else None),
771
- # ('finished', finished),
772
- # ('partial', partial)]
794
+ # metadata = [item for item in (('inspector', inspector), ('finished', finished), ('partial', partial))]
795
+ #
796
+ # if partial is True:
797
+ # finished = False
773
798
774
799
if len (inspector ) == 0 :
775
800
inspector = None
776
801
777
- #if partial is True:
778
- # finished = False
779
-
780
802
metadata = [item for item in (('inspector' , inspector ), ('finished' , finished ))]
781
803
self ._write_chunk (metadata , self ._buffer .getvalue ())
782
804
self ._clear ()
@@ -794,7 +816,7 @@ def write_metric(self, name, value):
794
816
self ._inspector ['metric.' + name ] = value
795
817
796
818
def _clear (self ):
797
- RecordWriter ._clear (self )
819
+ super ( RecordWriterV2 , self ) ._clear ()
798
820
self ._fieldnames = None
799
821
800
822
def _write_chunk (self , metadata , body ):
0 commit comments