You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/01/21 00:07:00 UTC

[jira] [Work logged] (GOBBLIN-1367) Fix PostgresqlExtractor's unnecessary string replacement

     [ https://issues.apache.org/jira/browse/GOBBLIN-1367?focusedWorklogId=538773&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-538773 ]

ASF GitHub Bot logged work on GOBBLIN-1367:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 21/Jan/21 00:06
            Start Date: 21/Jan/21 00:06
    Worklog Time Spent: 10m 
      Work Description: sekikn opened a new pull request #3209:
URL: https://github.com/apache/incubator-gobblin/pull/3209


   Dear Gobblin maintainers,
   
   Please accept this PR. I understand that it will not be reviewed until I have checked off all the steps below!
   
   
   ### JIRA
   - [x] My PR addresses the following [Gobblin JIRA](https://issues.apache.org/jira/browse/GOBBLIN/) issues and references them in the PR title. For example, "[GOBBLIN-XXX] My Gobblin PR"
       - https://issues.apache.org/jira/browse/GOBBLIN-1367
   
   
   ### Description
   - [x] Here are some details about my PR, including screenshots (if applicable):
   
   PostgresqlExtractor fails if the name of schema or table contains the one of its column as substring. This PR fixes it.
   
   ### Tests
   - [x] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:
   
   * o.a.g.source.jdbc.PostgresqlExtractorTest.testGetHighWatermarkMetadata
   * o.a.g.source.jdbc.PostgresqlExtractorTest.testGetCountMetadata
   
   ### Commits
   - [x] My commits all reference JIRA issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
       1. Subject is separated from body by a blank line
       2. Subject is limited to 50 characters
       3. Subject does not end with a period
       4. Subject uses the imperative mood ("add", not "adding")
       5. Body wraps at 72 characters
       6. Body explains "what" and "why", not "how"
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 538773)
    Remaining Estimate: 0h
            Time Spent: 10m

> Fix PostgresqlExtractor's unnecessary string replacement
> --------------------------------------------------------
>
>                 Key: GOBBLIN-1367
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-1367
>             Project: Apache Gobblin
>          Issue Type: Bug
>          Components: gobblin-sql
>            Reporter: Kengo Seki
>            Assignee: Shirshanka Das
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> I tried to run PostgreSQL Source/Extractor with the following minimal config,
> {code}
> $ psql
> psql (12.5 (Ubuntu 12.5-0ubuntu0.20.04.1))
> Type "help" for help.
> sekikn=# \c
> You are now connected to database "sekikn" as user "sekikn".
> sekikn=# \d
>  public | t    | table | sekikn
> sekikn=# \d t
>  c      | character varying |           |          | 
> {code}
> {code}
> $ cat ~/postgres_to_console.job 
> source.class=org.apache.gobblin.source.extractor.extract.jdbc.PostgresqlSource
> source.conn.driver=org.postgresql.Driver
> source.conn.username=sekikn
> source.conn.password=********
> source.conn.host=localhost
> source.conn.port=5432
> source.conn.database=sekikn
> source.querybased.schema=public
> source.entity=t
> extract.table.type=SNAPSHOT_APPEND
> writer.builder.class=org.apache.gobblin.writer.ConsoleWriterBuilder
> data.publisher.type=org.apache.gobblin.publisher.NoopPublisher
> {code}
> but came across the following error.
> {code}
> $ bin/gobblin cli run -jobName postgres_to_console -jobFile ~/postgres_to_console.job
> (snip)
> 2021-01-21 07:45:40 JST INFO  [gobblin-instance-driver] org.apache.gobblin.source.jdbc.JdbcExtractor [public_t_1611182740226_0] - Extract metadata using JDBC
> 2021-01-21 07:45:40 JST INFO  [gobblin-instance-driver] org.apache.gobblin.source.jdbc.JdbcExtractor [public_t_1611182740226_0] - Executing query:select col.column_name, col.data_type, case when CHARACTER_OCTET_LENGTH is null then 0 else 0 end as length, case when NUMERIC_PRECISION is null then 0 else NUMERIC_PRECISION end as precesion, case when NUMERIC_SCALE is null then 0 else NUMERIC_SCALE end as scale, case when is_nullable='NO' then 'false' else 'true' end as nullable, '' as format, '' as comment from information_schema.COLUMNS col WHERE upper(col.table_name)=upper(?) AND upper(col.table_schema)=upper(?) order by col.ORDINAL_POSITION
> 2021-01-21 07:45:40 JST INFO  [gobblin-instance-driver] org.apache.gobblin.source.jdbc.JdbcExtractor [public_t_1611182740226_0] - Schema:[{"columnName":"c","dataType":{"type":"string"},"isWaterMark":false,"primaryKey":0,"length":0,"precision":0,"scale":0,"isNullable":true,"format":"","comment":"","isUnique":false}]
> 2021-01-21 07:45:40 JST INFO  [gobblin-instance-driver] org.apache.gobblin.source.jdbc.JdbcExtractor [public_t_1611182740226_0] - Extract query: SELECT c FROM public.t where ('$WATERMARK')
> 2021-01-21 07:45:40 JST INFO  [gobblin-instance-driver] org.apache.gobblin.source.jdbc.JdbcExtractor [public_t_1611182740226_0] - Get source record count using JDBC
> 2021-01-21 07:45:40 JST INFO  [gobblin-instance-driver] org.apache.gobblin.source.jdbc.JdbcExtractor [public_t_1611182740226_0] - Executing query:SELECT COUNT(1) FROM publiCOUNT(1).t where (1=1)
> 2021-01-21 07:45:40 JST ERROR [gobblin-instance-driver] org.apache.gobblin.source.jdbc.JdbcExtractor [public_t_1611182740226_0] - Failed to execute sql:SELECT COUNT(1) FROM publiCOUNT(1).t where (1=1) ;error-ERROR: syntax error at or near "."
>   Position: 35
> org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
>   Position: 35
> 	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2477)
> 	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)
> 	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
> 	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
> 	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
> 	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
> 	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
> 	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
> 	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260)
> 	at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
> 	at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
> 	at org.apache.gobblin.source.jdbc.JdbcExtractor.executeSql(JdbcExtractor.java:666)
> 	at org.apache.gobblin.source.jdbc.JdbcExtractor.getSourceCount(JdbcExtractor.java:797)
> 	at org.apache.gobblin.source.extractor.extract.QueryBasedExtractor.build(QueryBasedExtractor.java:326)
> 	at org.apache.gobblin.source.extractor.extract.jdbc.PostgresqlSource.getExtractor(PostgresqlSource.java:47)
> 	at org.apache.gobblin.runtime.TaskContext.getExtractor(TaskContext.java:120)
> 	at org.apache.gobblin.runtime.Task.<init>(Task.java:196)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt.createTaskRunnable(GobblinMultiTaskAttempt.java:485)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt.access$100(GobblinMultiTaskAttempt.java:86)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt$2.call(GobblinMultiTaskAttempt.java:511)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt$2.call(GobblinMultiTaskAttempt.java:505)
> 	at com.github.rholder.retry.AttemptTimeLimiters$NoAttemptTimeLimit.call(AttemptTimeLimiters.java:78)
> 	at com.github.rholder.retry.Retryer.call(Retryer.java:160)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt.createTaskWithRetry(GobblinMultiTaskAttempt.java:505)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt.runWorkUnits(GobblinMultiTaskAttempt.java:421)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt.run(GobblinMultiTaskAttempt.java:157)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt.runAndOptionallyCommitTaskAttempt(GobblinMultiTaskAttempt.java:521)
> 	at org.apache.gobblin.runtime.GobblinMultiTaskAttempt.runWorkUnits(GobblinMultiTaskAttempt.java:563)
> 	at org.apache.gobblin.runtime.local.LocalJobLauncher.runWorkUnitStream(LocalJobLauncher.java:156)
> 	at org.apache.gobblin.runtime.AbstractJobLauncher.launchJob(AbstractJobLauncher.java:508)
> 	at org.apache.gobblin.runtime.job_exec.JobLauncherExecutionDriver$DriverRunnable.call(JobLauncherExecutionDriver.java:164)
> 	at org.apache.gobblin.runtime.job_exec.JobLauncherExecutionDriver$DriverRunnable.call(JobLauncherExecutionDriver.java:152)
> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> 	at java.lang.Thread.run(Thread.java:748)
> 2021-01-21 07:45:40 JST ERROR [gobblin-instance-driver] org.apache.gobblin.source.extractor.extract.jdbc.PostgresqlSource [public_t_1611182740226_0] - Failed to prepare extractor: error - Failed to get record count; error - Failed to get source record count using JDBC; error - Failed to get source record count from database; error - null
> {code}
> This is because the target schema and table (publi"c".t) contains the name of column (c), so it was replaced wrongly. PostgresqlExtractor should replace only the first occurrence of the target substring here.
>  [https://github.com/apache/incubator-gobblin/blob/release-0.15.0/gobblin-modules/gobblin-sql/src/main/java/org/apache/gobblin/source/jdbc/PostgresqlExtractor.java#L134]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)