@@ -63,6 +63,7 @@ public SessionDataSet(string sql, TSExecuteStatementResp resp, ConcurrentClientQ
63
63
_currentBitmap = new byte [ _columnSize ] ;
64
64
_columnNames = new List < string > ( ) ;
65
65
_timeBuffer = new ByteBuffer ( _queryDataset . Time ) ;
66
+ // column name -> column location
66
67
_columnNameIndexMap = new Dictionary < string , int > ( ) ;
67
68
_columnTypeLst = new List < string > ( ) ;
68
69
_duplicateLocation = new Dictionary < int , int > ( ) ;
@@ -72,43 +73,31 @@ public SessionDataSet(string sql, TSExecuteStatementResp resp, ConcurrentClientQ
72
73
_hasCatchedResult = false ;
73
74
_rowIndex = 0 ;
74
75
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
- }
95
76
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 ++ ;
106
99
}
107
-
108
- _valueBufferLst . Add ( new ByteBuffer ( _queryDataset . ValueList [ index ] ) ) ;
109
- _bitmapBufferLst . Add ( new ByteBuffer ( _queryDataset . BitmapList [ index ] ) ) ;
110
100
}
111
-
112
101
}
113
102
public List < string > ColumnNames => _columnNames ;
114
103
@@ -282,8 +271,10 @@ private bool FetchResults()
282
271
_bitmapBufferLst = new List < ByteBuffer > ( ) ;
283
272
for ( int index = 0 ; index < _queryDataset . ValueList . Count ; index ++ )
284
273
{
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 ] ) ) ;
287
278
}
288
279
289
280
// reset row index
0 commit comments