Skip to content

Beam-2383 Round function#3326

Closed
app-tarush wants to merge 2 commits into
apache:DSL_SQLfrom
app-tarush:beam-2383-round-func
Closed

Beam-2383 Round function#3326
app-tarush wants to merge 2 commits into
apache:DSL_SQLfrom
app-tarush:beam-2383-round-func

Conversation

@app-tarush
Copy link
Copy Markdown
Contributor

Be sure to do all of the following to help us incorporate your contribution
quickly and easily:

  • Make sure the PR title is formatted like:
    [BEAM-<Jira issue #>] Description of pull request
  • Make sure tests pass via mvn clean verify.
  • Replace <Jira issue #> in the title with the actual Jira issue
    number, if there is one.
  • If this contribution is large, please file an Apache
    Individual Contributor License Agreement.

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling fec5f15 on app-tarush:beam-2383-round-func into ** on apache:DSL_SQL**.

@app-tarush
Copy link
Copy Markdown
Contributor Author

@xumingmin please review this PR #3326

@aaltay
Copy link
Copy Markdown
Member

aaltay commented Jun 8, 2017

R: @xumingmin @takidau

@mingmxu
Copy link
Copy Markdown

mingmxu commented Jun 8, 2017

@xumingming can you take a peak here?

Copy link
Copy Markdown
Contributor

@takidau takidau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, some initial comments.

return result;
}

private int roundInt(int v1, int v2) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what purpose these round* methods serve. They obscure the fact that SqlFunctions.sround is the same (overloaded) method being used in all cases, but don't really seem to provide much. Do they just exist to have shorter names?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@takidau they are to serve shorter names you got it correct

}

@Test public void testRoundFunction() {
// operands are of type long, int, tinyint
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't make sense to me. The operands immediately following are doubles.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@takidau I will correct it to make it more meaningfull

operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.0));
operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 4.0));
assertEquals(2.0, new BeamSqlRoundExpression(operands).evaluate(record).getValue());
// operands are of type decimal, double, big decimal
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@takidau I will correct it to make it more meaningfull

operands.add(ref0);
operands.add(BeamSqlPrimitive.of(SqlTypeName.BIGINT, 2L));

assertEquals(1234567L, new BeamSqlRoundExpression(operands).evaluate(record).getValue());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this one. Where is 1234567 coming from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@takidau this refers to BeamSqlInputRefExpression which means first index value we are referencing. Lets suppose I have one row which represents a record with 4 columns

record.addField(0, 1234567L);
    record.addField(1, 0);
    record.addField(2, 8.9);
    record.addField(3, 1234567L);

now BeamSqlInputRefExpression helps in referencing a column :

BeamSqlInputRefExpression ref0 = new BeamSqlInputRefExpression(SqlTypeName.BIGINT, 0);
public class BeamSQLFnExecutorTestBase {
  public static RexBuilder rexBuilder = new RexBuilder(BeamQueryPlanner.TYPE_FACTORY);
  public static RelOptCluster cluster = RelOptCluster.create(new VolcanoPlanner(), rexBuilder);

  public static final JavaTypeFactory TYPE_FACTORY = new JavaTypeFactoryImpl(
      RelDataTypeSystem.DEFAULT);
  public static RelDataType relDataType;

  public static BeamSQLRecordType beamRecordType;
  public static BeamSQLRow record;

  public static RelBuilder relBuilder;

  @BeforeClass
  public static void prepare() {
    relDataType = TYPE_FACTORY.builder()
        .add("order_id", SqlTypeName.BIGINT)
        .add("site_id", SqlTypeName.INTEGER)
        .add("price", SqlTypeName.DOUBLE)
        .add("order_time", SqlTypeName.BIGINT).build();

    beamRecordType = BeamSQLRecordType.from(relDataType);
    record = new BeamSQLRow(beamRecordType);

    record.addField(0, 1234567L);
    record.addField(1, 0);
    record.addField(2, 8.9);
    record.addField(3, 1234567L);

    SchemaPlus schema = Frameworks.createRootSchema(true);
    final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
    traitDefs.add(ConventionTraitDef.INSTANCE);
    traitDefs.add(RelCollationTraitDef.INSTANCE);
    FrameworkConfig config = Frameworks.newConfigBuilder()
        .parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build()).defaultSchema(schema)
        .traitDefs(traitDefs).context(Contexts.EMPTY_CONTEXT).ruleSets(BeamRuleSets.getRuleSets())
        .costFactory(null).typeSystem(BeamRelDataTypeSystem.BEAM_REL_DATATYPE_SYSTEM).build();

    relBuilder = RelBuilder.create(config);
  }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it, thanks!

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 715883f on app-tarush:beam-2383-round-func into ** on apache:DSL_SQL**.

@app-tarush
Copy link
Copy Markdown
Contributor Author

@takidau I have made changes in comments.

@takidau
Copy link
Copy Markdown
Contributor

takidau commented Jun 13, 2017

To clarify, are you wanting to pull this change before #3336, or are you wanting to submit POWER and ROUND together with just that new PR? I think this one is probably ready to go from my perspective.

@app-tarush
Copy link
Copy Markdown
Contributor Author

@takidau I am good if this pull with change #3326 can go before POWER #3336.

@takidau
Copy link
Copy Markdown
Contributor

takidau commented Jun 13, 2017

Great, I'll go ahead and pull this one then. LGTM.

@app-tarush
Copy link
Copy Markdown
Contributor Author

@takidau thanks!! 👍

asfgit pushed a commit that referenced this pull request Jun 13, 2017
@takidau
Copy link
Copy Markdown
Contributor

takidau commented Jun 13, 2017

Merged on branch DSL_SQL. I updated to include the SQL → Sql renames as part of it. Feel free to close this PR. Thanks!

@app-tarush app-tarush closed this Jun 16, 2017
@app-tarush
Copy link
Copy Markdown
Contributor Author

app-tarush commented Jun 16, 2017

[Beam-2383] This closes PR #3326.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants