[ https://issues.apache.org/jira/browse/STORM-699?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14356353#comment-14356353 ]
ASF GitHub Bot commented on STORM-699: -------------------------------------- Github user HeartSaVioR commented on a diff in the pull request: https://github.com/apache/storm/pull/458#discussion_r26190228 --- Diff: external/storm-jdbc/README.md --- @@ -38,34 +63,30 @@ hikariConfigMap.put("dataSource.password","password"); String tableName = "user_details"; JdbcMapper simpleJdbcMapper = new SimpleJdbcMapper(tableName, map); ``` -The mapper initialized in the example above assumes a storm tuple has value for all the columns. -If your storm tuple only has fields for a subset of columns i.e. if some of the columns in your table have default values -and you want to only insert values for columns with no default values you can enforce the behavior by initializing the -`SimpleJdbcMapper` with explicit columnschema. For example, if you have a user_details table -`create table if not exists user_details (user_id integer, user_name varchar(100), dept_name varchar(100), create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP);` -In this table the create_time column has a default value. To ensure only the columns with no default values are inserted -you can initialize the `jdbcMapper` as below: +The mapper initialized in the example above assumes a storm tuple has value for all the columns of the table you intend to insert data into and its `getColumn` +method will return the columns in the order in which Jdbc connection instance's `connection.getMetaData().getColumns();` method returns them. +**If you specified your own insert query to `JdbcInsertBolt` you must initialize `SimpleJdbcMapper` with explicit columnschema such that the schema has columns in the same order as your insert queries.** +For example if your insert query is `Insert into user (user_id, user_name) values (?,?)` then your `SimpleJdbcMapper` should be initialized with the following statements: ```java List<Column> columnSchema = Lists.newArrayList( new Column("user_id", java.sql.Types.INTEGER), - new Column("user_name", java.sql.Types.VARCHAR)); - JdbcMapper simpleJdbcMapper = new SimpleJdbcMapper(columnSchema); + new Column("user_name", java.sql.Types.VARCHAR), --- End diff -- Codes in comments seems broken. Could you have a look? > storm-jdbc should support customer insert queries. > -------------------------------------------------- > > Key: STORM-699 > URL: https://issues.apache.org/jira/browse/STORM-699 > Project: Apache Storm > Issue Type: Improvement > Affects Versions: 0.10.0 > Reporter: Parth Brahmbhatt > Assignee: Parth Brahmbhatt > Priority: Minor > > Currently storm-jdbc insert bolt/state only supports to specify a table name > and constructs a query of the form "insert into tablename values(?,?,?)" > based on table's schema. This fails to support use cases like "insert into as > select * from" or special cases like Phoenix that has a jdbc driver but only > supports "upsert into". > We should add a way so the users can specify their own custom query for the > insert bolt. This was already pointed out by [~revans2] during the PR review > and we now have concrete cases that will be benefited by this feature. -- This message was sent by Atlassian JIRA (v6.3.4#6332)