@@ -63,6 +63,7 @@ public SessionDataSet(string sql, TSExecuteStatementResp resp, ConcurrentClientQ
6363 _currentBitmap = new byte [ _columnSize ] ;
6464 _columnNames = new List < string > ( ) ;
6565 _timeBuffer = new ByteBuffer ( _queryDataset . Time ) ;
66+ // column name -> column location
6667 _columnNameIndexMap = new Dictionary < string , int > ( ) ;
6768 _columnTypeLst = new List < string > ( ) ;
6869 _duplicateLocation = new Dictionary < int , int > ( ) ;
@@ -72,43 +73,31 @@ public SessionDataSet(string sql, TSExecuteStatementResp resp, ConcurrentClientQ
7273 _hasCatchedResult = false ;
7374 _rowIndex = 0 ;
7475 RowCount = _queryDataset . Time . Length / sizeof ( long ) ;
75- if ( resp . ColumnNameIndexMap != null )
76- {
77- for ( var index = 0 ; index < resp . Columns . Count ; index ++ )
78- {
79- _columnNames . Add ( "" ) ;
80- _columnTypeLst . Add ( "" ) ;
81- }
82-
83- for ( var index = 0 ; index < resp . Columns . Count ; index ++ )
84- {
85- var name = resp . Columns [ index ] ;
86- _columnNames [ resp . ColumnNameIndexMap [ name ] ] = name ;
87- _columnTypeLst [ resp . ColumnNameIndexMap [ name ] ] = resp . DataTypeList [ index ] ;
88- }
89- }
90- else
91- {
92- _columnNames = resp . Columns ;
93- _columnTypeLst = resp . DataTypeList ;
94- }
9576
96- for ( int index = 0 ; index < _columnNames . Count ; index ++ )
97- {
98- var columnName = _columnNames [ index ] ;
99- if ( _columnNameIndexMap . ContainsKey ( columnName ) )
100- {
101- _duplicateLocation [ index ] = _columnNameIndexMap [ columnName ] ;
102- }
103- else
104- {
105- _columnNameIndexMap [ columnName ] = index ;
77+ _columnNames = resp . Columns ;
78+ _columnTypeLst = resp . DataTypeList ;
79+
80+ int deduplicateIdx = 0 ;
81+ Dictionary < string , int > columnToFirstIndexMap = new Dictionary < string , int > ( ) ;
82+ for ( var i = 0 ; i < _columnSize ; i ++ ) {
83+ var columnName = _columnNames [ i ] ;
84+ if ( _columnNameIndexMap . ContainsKey ( columnName ) ) {
85+ _duplicateLocation [ i ] = columnToFirstIndexMap [ columnName ] ;
86+ } else {
87+ columnToFirstIndexMap [ columnName ] = i ;
88+ if ( resp . ColumnNameIndexMap != null ) {
89+ int valueIndex = resp . ColumnNameIndexMap [ columnName ] ;
90+ _columnNameIndexMap [ columnName ] = valueIndex ;
91+ _valueBufferLst . Add ( new ByteBuffer ( _queryDataset . ValueList [ valueIndex ] ) ) ;
92+ _bitmapBufferLst . Add ( new ByteBuffer ( _queryDataset . BitmapList [ valueIndex ] ) ) ;
93+ } else {
94+ _columnNameIndexMap [ columnName ] = deduplicateIdx ;
95+ _valueBufferLst . Add ( new ByteBuffer ( _queryDataset . ValueList [ deduplicateIdx ] ) ) ;
96+ _bitmapBufferLst . Add ( new ByteBuffer ( _queryDataset . BitmapList [ deduplicateIdx ] ) ) ;
97+ }
98+ deduplicateIdx ++ ;
10699 }
107-
108- _valueBufferLst . Add ( new ByteBuffer ( _queryDataset . ValueList [ index ] ) ) ;
109- _bitmapBufferLst . Add ( new ByteBuffer ( _queryDataset . BitmapList [ index ] ) ) ;
110100 }
111-
112101 }
113102 public List < string > ColumnNames => _columnNames ;
114103
@@ -282,8 +271,10 @@ private bool FetchResults()
282271 _bitmapBufferLst = new List < ByteBuffer > ( ) ;
283272 for ( int index = 0 ; index < _queryDataset . ValueList . Count ; index ++ )
284273 {
285- _valueBufferLst . Add ( new ByteBuffer ( _queryDataset . ValueList [ index ] ) ) ;
286- _bitmapBufferLst . Add ( new ByteBuffer ( _queryDataset . BitmapList [ index ] ) ) ;
274+ string columnName = _columnNames [ index ] ;
275+ int valueIndex = _columnNameIndexMap [ columnName ] ;
276+ _valueBufferLst . Add ( new ByteBuffer ( _queryDataset . ValueList [ valueIndex ] ) ) ;
277+ _bitmapBufferLst . Add ( new ByteBuffer ( _queryDataset . BitmapList [ valueIndex ] ) ) ;
287278 }
288279
289280 // reset row index
0 commit comments