2626import com .dtstack .flink .sql .side .cache .AbstractSideCache ;
2727import com .dtstack .flink .sql .side .cache .CacheObj ;
2828import com .dtstack .flink .sql .side .cache .LRUSideCache ;
29+ import com .dtstack .flink .sql .util .RowDataConvert ;
2930import com .dtstack .flink .sql .util .ReflectionUtils ;
3031import com .google .common .collect .Lists ;
3132import com .google .common .collect .Maps ;
3738import org .apache .flink .metrics .Counter ;
3839import org .apache .flink .streaming .api .functions .async .ResultFuture ;
3940import org .apache .flink .streaming .api .functions .async .RichAsyncFunction ;
41+ import org .apache .flink .table .dataformat .BaseRow ;
4042import org .apache .flink .streaming .api .operators .StreamingRuntimeContext ;
41- import org .apache .flink .streaming .runtime .tasks .ProcessingTimeCallback ;
4243import org .apache .flink .streaming .runtime .tasks .ProcessingTimeService ;
4344import org .apache .flink .table .api .DataTypes ;
4445import org .apache .flink .types .Row ;
6263 * @author xuchao
6364 */
6465
65- public abstract class BaseAsyncReqRow extends RichAsyncFunction <Tuple2 <Boolean ,Row >, Tuple2 <Boolean ,Row >> implements ISideReqRow {
66+ public abstract class BaseAsyncReqRow extends RichAsyncFunction <Tuple2 <Boolean ,Row >, Tuple2 <Boolean ,BaseRow >> implements ISideReqRow {
6667 private static final Logger LOG = LoggerFactory .getLogger (BaseAsyncReqRow .class );
6768 private static final long serialVersionUID = 2098635244857937717L ;
6869 private RuntimeContext runtimeContext ;
@@ -131,12 +132,13 @@ protected boolean openCache(){
131132 return sideInfo .getSideCache () != null ;
132133 }
133134
134- protected void dealMissKey (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture ){
135+ protected void dealMissKey (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture ){
135136 if (sideInfo .getJoinType () == JoinType .LEFT ){
136137 //Reserved left table data
137138 try {
138139 Row row = fillData (input .f1 , null );
139- resultFuture .complete (Collections .singleton (new Tuple2 <>(input .f0 , row )));
140+ BaseRow baseRow = RowDataConvert .convertToBaseRow (row );
141+ resultFuture .complete (Collections .singleton (new Tuple2 <>(input .f0 , baseRow )));
140142 } catch (Exception e ) {
141143 dealFillDataError (input , resultFuture , e );
142144 }
@@ -152,7 +154,7 @@ protected void dealCacheData(String key, CacheObj missKeyObj) {
152154 }
153155
154156 @ Override
155- public void timeout (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture ) throws Exception {
157+ public void timeout (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture ) throws Exception {
156158
157159 if (timeOutNum % TIMEOUT_LOG_FLUSH_NUM == 0 ){
158160 LOG .info ("Async function call has timed out. input:{}, timeOutNum:{}" ,input .toString (), timeOutNum );
@@ -169,13 +171,13 @@ public void timeout(Tuple2<Boolean,Row> input, ResultFuture<Tuple2<Boolean,Row>>
169171 resultFuture .complete (null );
170172 }
171173
172- protected void preInvoke (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture )
174+ protected void preInvoke (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture )
173175 throws InvocationTargetException , IllegalAccessException {
174176 registerTimerAndAddToHandler (input , resultFuture );
175177 }
176178
177179 @ Override
178- public void asyncInvoke (Tuple2 <Boolean ,Row > row , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture ) throws Exception {
180+ public void asyncInvoke (Tuple2 <Boolean ,Row > row , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture ) throws Exception {
179181 Tuple2 <Boolean ,Row > input = Tuple2 .of (row .f0 , Row .copy (row .f1 ));
180182 preInvoke (input , resultFuture );
181183 Map <String , Object > inputParams = parseInputParam (input );
@@ -208,7 +210,7 @@ protected boolean isUseCache(Map<String, Object> inputParams){
208210 return openCache () && getFromCache (buildCacheKey (inputParams )) != null ;
209211 }
210212
211- private void invokeWithCache (Map <String , Object > inputParams , Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture ){
213+ private void invokeWithCache (Map <String , Object > inputParams , Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture ){
212214 if (openCache ()) {
213215 CacheObj val = getFromCache (buildCacheKey (inputParams ));
214216 if (val != null ) {
@@ -218,16 +220,18 @@ private void invokeWithCache(Map<String, Object> inputParams, Tuple2<Boolean,Row
218220 }else if (ECacheContentType .SingleLine == val .getType ()){
219221 try {
220222 Row row = fillData (input .f1 , val .getContent ());
221- resultFuture .complete (Collections .singleton (Tuple2 .of (input .f0 , row )));
223+ BaseRow baseRow = RowDataConvert .convertToBaseRow (row );
224+ resultFuture .complete (Collections .singleton (Tuple2 .of (input .f0 , baseRow )));
222225 } catch (Exception e ) {
223226 dealFillDataError (input , resultFuture , e );
224227 }
225228 } else if (ECacheContentType .MultiLine == val .getType ()) {
226229 try {
227- List <Tuple2 <Boolean ,Row >> rowList = Lists .newArrayList ();
230+ List <Tuple2 <Boolean ,BaseRow >> rowList = Lists .newArrayList ();
228231 for (Object one : (List ) val .getContent ()) {
229232 Row row = fillData (input .f1 , one );
230- rowList .add (Tuple2 .of (input .f0 , row ));
233+ BaseRow baseRow = RowDataConvert .convertToBaseRow (row );
234+ rowList .add (Tuple2 .of (input .f0 , baseRow ));
231235 }
232236 resultFuture .complete (rowList );
233237 } catch (Exception e ) {
@@ -241,22 +245,22 @@ private void invokeWithCache(Map<String, Object> inputParams, Tuple2<Boolean,Row
241245 }
242246 }
243247
244- public abstract void handleAsyncInvoke (Map <String , Object > inputParams , Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture ) throws Exception ;
248+ public abstract void handleAsyncInvoke (Map <String , Object > inputParams , Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture ) throws Exception ;
245249
246250 public abstract String buildCacheKey (Map <String , Object > inputParams );
247251
248252 private ProcessingTimeService getProcessingTimeService (){
249253 return ((StreamingRuntimeContext )this .runtimeContext ).getProcessingTimeService ();
250254 }
251255
252- protected ScheduledFuture <?> registerTimer (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture ){
256+ protected ScheduledFuture <?> registerTimer (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture ){
253257 long timeoutTimestamp = sideInfo .getSideTableInfo ().getAsyncTimeout () + getProcessingTimeService ().getCurrentProcessingTime ();
254258 return getProcessingTimeService ().registerTimer (
255259 timeoutTimestamp ,
256260 timestamp -> timeout (input , resultFuture ));
257261 }
258262
259- protected void registerTimerAndAddToHandler (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture )
263+ protected void registerTimerAndAddToHandler (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture )
260264 throws InvocationTargetException , IllegalAccessException {
261265 ScheduledFuture <?> timeFuture = registerTimer (input , resultFuture );
262266 // resultFuture 是ResultHandler 的实例
@@ -266,7 +270,7 @@ protected void registerTimerAndAddToHandler(Tuple2<Boolean,Row> input, ResultFut
266270 }
267271
268272
269- protected void dealFillDataError (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,Row >> resultFuture , Throwable e ) {
273+ protected void dealFillDataError (Tuple2 <Boolean ,Row > input , ResultFuture <Tuple2 <Boolean ,BaseRow >> resultFuture , Throwable e ) {
270274 parseErrorRecords .inc ();
271275 if (parseErrorRecords .getCount () > sideInfo .getSideTableInfo ().getAsyncFailMaxNum (Long .MAX_VALUE )){
272276 LOG .info ("dealFillDataError" , e );
0 commit comments