You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/03/16 15:08:25 UTC
[GitHub] [incubator-shardingsphere] terrymanu opened a new issue #4784:
Throw NPE when INSERT column and values mismatch
terrymanu opened a new issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784
Throw NullPointException when INSERT column and values mismatch.
It is better to throw suitable SQLException for JDBC-driver and proxy.
The tasks are:
- [ ] Throw suitable SQLException for JDBC-driver.
- [ ] Report suitable error packet with MySQL proxy.
- [ ] Report suitable error packet with PostgreSQL proxy.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] ranjeet-floyd commented on issue #4784:
Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
ranjeet-floyd commented on issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784#issuecomment-607946392
@terrymanu I modified test sql in class org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShadowPreparedStatementTest . Below is screen shot
<img width="1375" alt="Screenshot 2020-04-02 at 9 47 57 PM" src="https://user-images.githubusercontent.com/1992972/78272860-ae81b100-752b-11ea-8c5e-c8a388e036c4.png">
<img width="1644" alt="Screenshot 2020-04-02 at 9 45 13 PM" src="https://user-images.githubusercontent.com/1992972/78272744-8db95b80-752b-11ea-8dc1-ac33622bc5dc.png">
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] ranjeet-floyd commented on issue #4784:
Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
ranjeet-floyd commented on issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784#issuecomment-599666678
@terrymanu Can i take this ?. Thanks
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] ranjeet-floyd commented on issue #4784:
Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
ranjeet-floyd commented on issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784#issuecomment-605488820
@terrymanu Thanks but Not able to find it. Can you please point to class.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] terrymanu commented on issue #4784:
Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784#issuecomment-607015836
Have you run the sharding-proxy already?
Could you provided the SQL and exception info if `INSERT column and values mismatch`?
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] ranjeet-floyd commented on issue #4784:
Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
ranjeet-floyd commented on issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784#issuecomment-603642734
@terrymanu Can you please help me to find issue.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [shardingsphere] hitnewbee commented on issue #4784: Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
hitnewbee commented on issue #4784:
URL: https://github.com/apache/shardingsphere/issues/4784#issuecomment-632010619
I have add a judge code right after sqlstatement has been instantiated, with serveral test seem like it works for this issue. I think better way maybe :
1.make a judement method in CommonSQLStatementContext with default logic like return true directly;
2.if some subclass of CommonSQLStatementContext want to make their own judge method then override it.
I am not sure whether it will be a better way or not.
If you have some time, plz give me some advice. @menghaoranss
----------------------------------------------------------------
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
[GitHub] [shardingsphere] menghaoranss commented on issue #4784: Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
menghaoranss commented on issue #4784:
URL: https://github.com/apache/shardingsphere/issues/4784#issuecomment-629004883
@hk1997 ,I have tried to track this issue use sharidng-proxy with mysql :
`yaml`:
```
rules:
- !!org.apache.shardingsphere.sharding.core.yaml.config.sharding.YamlShardingRuleConfiguration
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithm:
type: INLINE
props:
algorithm.expression: t_order_${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_id
t_order_item:
actualDataNodes: ds_${0..1}.t_order_item_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithm:
type: INLINE
props:
algorithm.expression: t_order_item_${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_item_id
bindingTables:
- t_order,t_order_item
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithm:
type: INLINE
props:
algorithm.expression: ds_${user_id % 2}
defaultTableStrategy:
none:
```
`table`:
```
CREATE TABLE `t_order` (
`order_id` bigint(20) NOT NULL,
`user_id` int(11) NOT NULL,
`status` varchar(50) DEFAULT NULL,
PRIMARY KEY (`order_id`)
) ENGINE=InnoDB DEFAULT
```
`case`:
```
mysql> insert into t_order(user_id, status) values(1);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into t_order(order_id, user_id, status) values(201,200);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into t_order(user_id, status) values(1, 2, '3');
ERROR 10002 (C1000): 2Unknown exception: [null]
mysql> insert into t_order values(201,200,2000,200);
ERROR 10002 (C1000): 2Unknown exception: [null]
mysql> insert into t_order values(201,200);
Query OK, 1 row affected (6.66 sec)
mysql> insert into t_order values(201);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
```
there are 2 situations:
- use default cloumns
- values num > columns num :NPE
- values num = columns num - generatedKey num :OK
- values num < columns num - generatedKey num :excute ERROR
- designate columns
- values num > columns num :NPE
- values num < columns num :excute ERROR
And , i have debuged the source code , this is the code where NPE occured:
```
InsertClauseShardingConditionEngine.class
private ShardingCondition createShardingCondition(final String tableName, final Iterator<String> columnNames, final InsertValueContext insertValueContext, final List<Object> parameters) {
ShardingCondition result = new ShardingCondition();
SPITimeService timeService = new SPITimeService();
for (ExpressionSegment each : insertValueContext.getValueExpressions()) {
//NPE here
String columnName = columnNames.next();
if (shardingRule.isShardingColumn(columnName, tableName)) {
if (each instanceof SimpleExpressionSegment) {
result.getRouteValues().add(new ListRouteValue<>(columnName, tableName, Collections.singletonList(getRouteValue((SimpleExpressionSegment) each, parameters))));
} else if (ExpressionConditionUtils.isNowExpression(each)) {
result.getRouteValues().add(new ListRouteValue<>(columnName, tableName, Collections.singletonList(timeService.getTime())));
} else if (ExpressionConditionUtils.isNullExpression(each)) {
throw new ShardingSphereException("Insert clause sharding column can't be null.");
}
}
}
return result;
}
```
I think some verification needs to be done after `SQLStatementContext` been instantiated:
```
DataNodeRouter.class
private RouteContext createRouteContext(final SQLStatement sqlStatement, final String sql, final List<Object> parameters) {
try {
SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(metaData.getSchema().getSchemaMetaData(), sql, parameters, sqlStatement);
// maybe need check here
return new RouteContext(sqlStatementContext, parameters, new RouteResult());
// TODO should pass parameters for master-slave
} catch (final IndexOutOfBoundsException ex) {
return new RouteContext(new CommonSQLStatementContext(sqlStatement), parameters, new RouteResult());
}
}
```
welcome to talk about here.
----------------------------------------------------------------
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
[GitHub] [incubator-shardingsphere] terrymanu commented on issue #4784:
Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784#issuecomment-604335626
@ranjeet-floyd You can write a wrong SQL with mismatched count of insert columns and values, and then you can find the NPE entry.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [shardingsphere] hitnewbee edited a comment on issue #4784: Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
hitnewbee edited a comment on issue #4784:
URL: https://github.com/apache/shardingsphere/issues/4784#issuecomment-632010619
I have add a judge code right after sqlstatement has been instantiated, with serveral test seem like it works for this issue. I think better way maybe :
1.make a judement method in CommonSQLStatementContext with default logic like return true directly;
2.if some subclass of CommonSQLStatementContext want to make their own judge method then override it.
I am not sure whether it will be a better way or not.
plz give me some advice. @menghaoranss
----------------------------------------------------------------
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
[GitHub] [shardingsphere] hk1997 commented on issue #4784: Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
hk1997 commented on issue #4784:
URL: https://github.com/apache/shardingsphere/issues/4784#issuecomment-628450046
@terrymanu Is this issue still open?
If yes, can I try working on this?
----------------------------------------------------------------
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
[GitHub] [incubator-shardingsphere] terrymanu commented on issue #4784:
Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784#issuecomment-599858141
Welcome, I just assigned to you. @ranjeet-floyd
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [incubator-shardingsphere] terrymanu commented on issue #4784:
Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #4784: Throw NPE when INSERT column and values mismatch
URL: https://github.com/apache/incubator-shardingsphere/issues/4784#issuecomment-611871993
You may startup Sharding-Proxy, and connect with MySQL client. Then input error SQL, then you can find the error message in backend.
From the error message, you can find the class entry.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [shardingsphere] LingyaoLv commented on issue #4784: Throw NPE when INSERT column and values mismatch
Posted by GitBox <gi...@apache.org>.
LingyaoLv commented on issue #4784:
URL: https://github.com/apache/shardingsphere/issues/4784#issuecomment-1047454210
Hi @ranjeet-floyd
Would you still like to contribute and resolve this issue?
Please share a status update with the community, thank you.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org