Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spark lambdas #65

Merged
merged 2 commits into from
May 25, 2023

Conversation

NathanEckert
Copy link
Contributor

This PR solves the following issue:

In Spark SQL, it is possible to use lambda.

However, the formatter is breaking valid SQL statements:

import static org.assertj.core.api.Assertions.assertThat;

import com.github.vertical_blank.sqlformatter.SqlFormatter;
import com.github.vertical_blank.sqlformatter.languages.Dialect;
import org.junit.jupiter.api.Test;

public class TestFormatter {

	String SQL_INPUT = "SELECT aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x, acc -> acc * 10);";

	@Test
	public void testFormatter() {
		assertThat(SqlFormatter.of(Dialect.SparkSql).format(SQL_INPUT)).contains("->");

	}

}

The output is:

java.lang.AssertionError: 
Expecting actual:
  "SELECT
  aggregate(array(1, 2, 3), 0, (acc, x) - > acc + x, acc - > acc * 10);"
to contain:
  "->"

In order to be valid Spark SQL, the symbol -> should be kept as a whole and not split into - >

Copy link
Owner

@vertical-blank vertical-blank left a comment

Choose a reason for hiding this comment

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

@NathanEckert
Thanks for the PR.
Could you please run mvn spotless:apply and format the code?

@NathanEckert
Copy link
Contributor Author

mvn spotless:apply

Done

@vertical-blank vertical-blank merged commit 5120732 into vertical-blank:master May 25, 2023
@vertical-blank
Copy link
Owner

LGTM

@vertical-blank
Copy link
Owner

@NathanEckert
Copy link
Contributor Author

@NathanEckert I've released 2.0.4 to Maven Central. https://repo1.maven.org/maven2/com/github/vertical-blank/sql-formatter/2.0.4/

Thanks a lot !

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.

2 participants