@@ -50,6 +50,7 @@ public class JDBCResourceStore extends PushdownResourceStore {
50
50
private static final String META_TABLE_KEY = "META_TABLE_KEY" ;
51
51
private static final String META_TABLE_TS = "META_TABLE_TS" ;
52
52
private static final String META_TABLE_CONTENT = "META_TABLE_CONTENT" ;
53
+ private static final String DIALECT_OF_PG = "postgresql" ;
53
54
private static Logger logger = LoggerFactory .getLogger (JDBCResourceStore .class );
54
55
private JDBCConnectionManager connectionManager ;
55
56
@@ -123,6 +124,9 @@ public void execute(Connection connection) throws SQLException {
123
124
124
125
try {
125
126
String indexName = "IDX_" + META_TABLE_TS ;
127
+ if (DIALECT_OF_PG .equals (kylinConfig .getMetadataDialect ())) {
128
+ indexName += System .currentTimeMillis ();
129
+ }
126
130
String createIndexSql = sqls .getCreateIndexSql (indexName , tableName , META_TABLE_TS );
127
131
logger .info ("Creating index: {}" , createIndexSql );
128
132
pstat = connection .prepareStatement (createIndexSql );
@@ -314,7 +318,13 @@ private InputStream getInputStream(String resPath, ResultSet rs) throws SQLExcep
314
318
if (rs == null ) {
315
319
return null ;
316
320
}
317
-
321
+ if (DIALECT_OF_PG .equals (kylinConfig .getMetadataDialect ())) {
322
+ InputStream inputStream = rs .getBinaryStream (META_TABLE_CONTENT );
323
+ if (inputStream == null ) {
324
+ return openPushdown (resPath );
325
+ }
326
+ return inputStream ;
327
+ }
318
328
Blob blob = rs .getBlob (META_TABLE_CONTENT );
319
329
320
330
if (blob == null || blob .length () == 0 ) {
@@ -355,13 +365,13 @@ public void execute(Connection connection) throws SQLException, IOException {
355
365
if (existing ) {
356
366
pstat = connection .prepareStatement (sqls .getReplaceSql ());
357
367
pstat .setLong (1 , ts );
358
- pstat .setBlob (2 , new BufferedInputStream (new ByteArrayInputStream (bytes )));
368
+ pstat .setBinaryStream (2 , new BufferedInputStream (new ByteArrayInputStream (bytes )));
359
369
pstat .setString (3 , resPath );
360
370
} else {
361
371
pstat = connection .prepareStatement (sqls .getInsertSql ());
362
372
pstat .setString (1 , resPath );
363
373
pstat .setLong (2 , ts );
364
- pstat .setBlob (3 , new BufferedInputStream (new ByteArrayInputStream (bytes )));
374
+ pstat .setBinaryStream (3 , new BufferedInputStream (new ByteArrayInputStream (bytes )));
365
375
}
366
376
367
377
if (isContentOverflow (bytes , resPath )) {
@@ -376,8 +386,9 @@ public void execute(Connection connection) throws SQLException, IOException {
376
386
RollbackablePushdown pushdown = writePushdown (resPath , ContentWriter .create (bytes ));
377
387
try {
378
388
int result = pstat .executeUpdate ();
379
- if (result != 1 )
389
+ if (result != 1 ) {
380
390
throw new SQLException ();
391
+ }
381
392
} catch (Exception e ) {
382
393
pushdown .rollback ();
383
394
throw e ;
@@ -414,10 +425,11 @@ private boolean isContentOverflow(byte[] content, String resPath) throws SQLExce
414
425
}
415
426
416
427
int maxSize = kylinConfig .getJdbcResourceStoreMaxCellSize ();
417
- if (content .length > maxSize )
428
+ if (content .length > maxSize ) {
418
429
return true ;
419
- else
430
+ } else {
420
431
return false ;
432
+ }
421
433
}
422
434
423
435
@ Override
@@ -454,8 +466,9 @@ public void execute(Connection connection) throws SQLException, IOException {
454
466
RollbackablePushdown pushdown = writePushdown (resPath , ContentWriter .create (content ));
455
467
try {
456
468
int result = pstat .executeUpdate ();
457
- if (result != 1 )
469
+ if (result != 1 ) {
458
470
throw new SQLException ();
471
+ }
459
472
} catch (Throwable e ) {
460
473
pushdown .rollback ();
461
474
throw e ;
@@ -466,7 +479,7 @@ public void execute(Connection connection) throws SQLException, IOException {
466
479
pstat = connection .prepareStatement (sqls .getInsertSql ());
467
480
pstat .setString (1 , resPath );
468
481
pstat .setLong (2 , newTS );
469
- pstat .setBlob (3 , new BufferedInputStream (new ByteArrayInputStream (content )));
482
+ pstat .setBinaryStream (3 , new BufferedInputStream (new ByteArrayInputStream (content )));
470
483
pstat .executeUpdate ();
471
484
}
472
485
} else {
@@ -481,8 +494,9 @@ public void execute(Connection connection) throws SQLException, IOException {
481
494
RollbackablePushdown pushdown = writePushdown (resPath , ContentWriter .create (content ));
482
495
try {
483
496
int result = pstat .executeUpdate ();
484
- if (result != 1 )
497
+ if (result != 1 ) {
485
498
throw new SQLException ();
499
+ }
486
500
} catch (Throwable e ) {
487
501
pushdown .rollback ();
488
502
throw e ;
@@ -647,4 +661,4 @@ abstract static class SqlOperation {
647
661
abstract public void execute (final Connection connection ) throws SQLException , IOException ;
648
662
}
649
663
650
- }
664
+ }
0 commit comments