3535import com .dtstack .chunjun .element .column .BytesColumn ;
3636import com .dtstack .chunjun .element .column .NullColumn ;
3737import com .dtstack .chunjun .element .column .StringColumn ;
38+ import com .dtstack .chunjun .element .column .TimestampColumn ;
3839
3940import org .apache .flink .table .data .RowData ;
4041import org .apache .flink .table .types .logical .LogicalType ;
5758public class InfluxdbColumnConverter
5859 extends AbstractRowConverter <Map <String , Object >, RowData , Point .Builder , LogicalType > {
5960
61+ private static final String TIME_KEY = "time" ;
62+
6063 private String format = "MSGPACK" ;
6164 private List <String > fieldNameList ;
6265 private List <FieldConf > fieldConfList ;
@@ -72,7 +75,8 @@ public InfluxdbColumnConverter(
7275 RowType rowType ,
7376 ChunJunCommonConf commonConf ,
7477 List <String > fieldNameList ,
75- String format ) {
78+ String format ,
79+ TimeUnit precision ) {
7680 super (rowType , commonConf );
7781 for (int i = 0 ; i < rowType .getFieldCount (); i ++) {
7882 toInternalConverters .add (
@@ -85,6 +89,7 @@ public InfluxdbColumnConverter(
8589 this .format = format ;
8690 this .fieldConfList = commonConf .getColumn ();
8791 this .fieldNameList = fieldNameList ;
92+ this .precision = precision ;
8893 }
8994
9095 public InfluxdbColumnConverter (
@@ -124,33 +129,49 @@ protected ISerializationConverter<Point.Builder> wrapIntoNullableExternalConvert
124129
125130 @ Override
126131 public RowData toInternal (Map <String , Object > input ) throws Exception {
127-
132+ int converterIndex = 0 ;
128133 if (fieldConfList .size () == 1
129134 && StringUtils .equals (ConstantValue .STAR_SYMBOL , fieldConfList .get (0 ).getName ())) {
130135 ColumnRowData result = new ColumnRowData (fieldNameList .size ());
131- for (int i = 0 ; i < fieldNameList .size (); i ++) {
132- Object field = input .get (fieldNameList .get (i ));
133- AbstractBaseColumn baseColumn =
134- (AbstractBaseColumn ) toInternalConverters .get (i ).deserialize (field );
136+ for (String fieldName : fieldNameList ) {
137+ AbstractBaseColumn baseColumn = setValue (input , fieldName , converterIndex );
135138 result .addField (baseColumn );
139+ converterIndex ++;
136140 }
137141 return result ;
138- }
139-
140- ColumnRowData result = new ColumnRowData (fieldConfList .size ());
141- int converterIndex = 0 ;
142- for (FieldConf fieldConf : fieldConfList ) {
143- AbstractBaseColumn baseColumn = null ;
144- if (StringUtils .isBlank (fieldConf .getValue ())) {
145- Object field = input .get (fieldConf .getName ());
146- baseColumn =
147- (AbstractBaseColumn )
148- toInternalConverters .get (converterIndex ).deserialize (field );
142+ } else {
143+ ColumnRowData result = new ColumnRowData (fieldConfList .size ());
144+ for (FieldConf fieldConf : fieldConfList ) {
145+ String fieldName = fieldConf .getName ();
146+ AbstractBaseColumn baseColumn = setValue (input , fieldName , converterIndex );
147+ result .addField (assembleFieldProps (fieldConf , baseColumn ));
149148 converterIndex ++;
150149 }
151- result .addField (assembleFieldProps (fieldConf , baseColumn ));
150+ return result ;
151+ }
152+ }
153+
154+ /**
155+ * Set the value of input into column.
156+ *
157+ * @param input input value.
158+ * @param fieldName field name of input.
159+ * @param index index of converter.
160+ * @return column
161+ * @throws Exception the exception from converter.
162+ */
163+ private AbstractBaseColumn setValue (Map <String , Object > input , String fieldName , int index )
164+ throws Exception {
165+ AbstractBaseColumn baseColumn ;
166+ if (TIME_KEY .equalsIgnoreCase (fieldName )) {
167+ Long timeLong = (Long ) input .get (fieldName );
168+ long timeMs = TimeUnit .MILLISECONDS .convert (timeLong , precision );
169+ baseColumn = new TimestampColumn (timeMs );
170+ } else {
171+ Object field = input .get (fieldName );
172+ baseColumn = (AbstractBaseColumn ) toInternalConverters .get (index ).deserialize (field );
152173 }
153- return result ;
174+ return baseColumn ;
154175 }
155176
156177 @ Override
0 commit comments