use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class XmlBuilderTest method toStringEmptyElementLayout.
@Test
public void toStringEmptyElementLayout() {
@Language("XML") String expected = "<LinearLayout>\n" + "\n" + "</LinearLayout>\n";
String actual = new XmlBuilder().startTag("LinearLayout").endTag("LinearLayout").toString();
assertEquals(expected, actual);
}
use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class XmlBuilderTest method toStringTabHost.
@Test
public void toStringTabHost() {
@Language("XML") String expected = "<TabHost\n" + " android:layout_width=\"200dip\"\n" + " android:layout_height=\"300dip\">\n" + "\n" + " <LinearLayout\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"match_parent\"\n" + " android:orientation=\"vertical\">\n" + "\n" + " <TabWidget\n" + " android:id=\"@android:id/tabs\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"wrap_content\" />\n" + "\n" + " <FrameLayout\n" + " android:id=\"@android:id/tab_content\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"match_parent\">\n" + "\n" + " <LinearLayout\n" + " android:id=\"@+id/tab_1\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"match_parent\"\n" + " android:orientation=\"vertical\">\n" + "\n" + " </LinearLayout>\n" + "\n" + " <LinearLayout\n" + " android:id=\"@+id/tab_2\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"match_parent\"\n" + " android:orientation=\"vertical\">\n" + "\n" + " </LinearLayout>\n" + "\n" + " <LinearLayout\n" + " android:id=\"@+id/tab_3\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"match_parent\"\n" + " android:orientation=\"vertical\">\n" + "\n" + " </LinearLayout>\n" + " </FrameLayout>\n" + " </LinearLayout>\n" + "</TabHost>\n";
// @formatter:off
XmlBuilder builder = new XmlBuilder().startTag("TabHost").androidAttribute(SdkConstants.ATTR_LAYOUT_WIDTH, "200dip").androidAttribute(SdkConstants.ATTR_LAYOUT_HEIGHT, "300dip").startTag("LinearLayout").androidAttribute(SdkConstants.ATTR_LAYOUT_WIDTH, SdkConstants.VALUE_MATCH_PARENT).androidAttribute(SdkConstants.ATTR_LAYOUT_HEIGHT, SdkConstants.VALUE_MATCH_PARENT).androidAttribute("orientation", "vertical").startTag("TabWidget").androidAttribute("id", "@android:id/tabs").androidAttribute(SdkConstants.ATTR_LAYOUT_WIDTH, SdkConstants.VALUE_MATCH_PARENT).androidAttribute(SdkConstants.ATTR_LAYOUT_HEIGHT, SdkConstants.VALUE_WRAP_CONTENT).endTag("TabWidget").startTag("FrameLayout").androidAttribute("id", "@android:id/tab_content").androidAttribute(SdkConstants.ATTR_LAYOUT_WIDTH, SdkConstants.VALUE_MATCH_PARENT).androidAttribute(SdkConstants.ATTR_LAYOUT_HEIGHT, SdkConstants.VALUE_MATCH_PARENT);
for (int i = 0; i < 3; i++) {
builder.startTag("LinearLayout").androidAttribute("id", "@+id/tab_" + (i + 1)).androidAttribute(SdkConstants.ATTR_LAYOUT_WIDTH, SdkConstants.VALUE_MATCH_PARENT).androidAttribute(SdkConstants.ATTR_LAYOUT_HEIGHT, SdkConstants.VALUE_MATCH_PARENT).androidAttribute("orientation", "vertical").endTag("LinearLayout");
}
// @formatter:off
builder.endTag("FrameLayout").endTag("LinearLayout").endTag("TabHost");
// @formatter:on
assertEquals(expected, builder.toString());
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestSqlFunctions method testShowCreateFunctions.
public void testShowCreateFunctions() {
@Language("SQL") String createFunctionInt = "CREATE FUNCTION testing.common.array_append(a array<int>, x int)\n" + "RETURNS array<int>\n" + "RETURN concat(a, array[x])";
@Language("SQL") String createFunctionDouble = "CREATE FUNCTION testing.common.array_append(a array<double>, x double)\n" + "RETURNS array<double>\n" + "RETURN concat(a, array[x])";
@Language("SQL") String createFunctionRand = "CREATE FUNCTION testing.common.rand()\n" + "RETURNS double\n" + "RETURN rand()";
String createFunctionIntFormatted = "CREATE FUNCTION testing.common.array_append (\n" + " a ARRAY(integer),\n" + " x integer\n" + ")\n" + "RETURNS ARRAY(integer)\n" + "COMMENT ''\n" + "LANGUAGE SQL\n" + "NOT DETERMINISTIC\n" + "CALLED ON NULL INPUT\n" + "RETURN \"concat\"(a, ARRAY[x])";
String createFunctionDoubleFormatted = "CREATE FUNCTION testing.common.array_append (\n" + " a ARRAY(double),\n" + " x double\n" + ")\n" + "RETURNS ARRAY(double)\n" + "COMMENT ''\n" + "LANGUAGE SQL\n" + "NOT DETERMINISTIC\n" + "CALLED ON NULL INPUT\n" + "RETURN \"concat\"(a, ARRAY[x])";
String createFunctionRandFormatted = "CREATE FUNCTION testing.common.rand ()\n" + "RETURNS double\n" + "COMMENT ''\n" + "LANGUAGE SQL\n" + "NOT DETERMINISTIC\n" + "CALLED ON NULL INPUT\n" + "RETURN \"rand\"()";
String parameterTypeInt = "ARRAY(integer), integer";
String parameterTypeDouble = "ARRAY(double), double";
assertQuerySucceeds(createFunctionInt);
assertQuerySucceeds(createFunctionDouble);
assertQuerySucceeds(createFunctionRand);
MaterializedResult rows = computeActual("SHOW CREATE FUNCTION testing.common.array_append");
assertEquals(rows.getRowCount(), 2);
assertEquals(rows.getMaterializedRows().get(0).getFields(), ImmutableList.of(createFunctionDoubleFormatted, parameterTypeDouble));
assertEquals(rows.getMaterializedRows().get(1).getFields(), ImmutableList.of(createFunctionIntFormatted, parameterTypeInt));
rows = computeActual("SHOW CREATE FUNCTION testing.common.array_append(array(int), int)");
assertEquals(rows.getRowCount(), 1);
assertEquals(rows.getMaterializedRows().get(0).getFields(), ImmutableList.of(createFunctionIntFormatted, parameterTypeInt));
rows = computeActual("SHOW CREATE FUNCTION testing.common.rand()");
assertEquals(rows.getMaterializedRows().get(0).getFields(), ImmutableList.of(createFunctionRandFormatted, ""));
assertQueryFails("SHOW CREATE FUNCTION testing.common.array_append()", "Function not found: testing\\.common\\.array_append\\(\\)");
assertQueryFails("SHOW CREATE FUNCTION array_agg", "SHOW CREATE FUNCTION is only supported for SQL functions");
assertQueryFails("SHOW CREATE FUNCTION presto.default.array_agg", "SHOW CREATE FUNCTION is only supported for SQL functions");
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class RaptorQueryRunner method copyTable.
private static void copyTable(QueryRunner queryRunner, String catalog, Session session, String schema, TpchTable<?> table, String properties) {
QualifiedObjectName source = new QualifiedObjectName(catalog, schema, table.getTableName());
String target = table.getTableName();
String with = properties.isEmpty() ? "" : format(" WITH (%s)", properties);
@Language("SQL") String sql = format("CREATE TABLE %s%s AS SELECT * FROM %s", target, with, source);
log.info("Running import for %s", target);
long start = System.nanoTime();
long rows = queryRunner.execute(session, sql).getUpdateCount().getAsLong();
log.info("Imported %s rows for %s in %s", rows, target, nanosSince(start));
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class AbstractTestEngineOnlyQueries method testLocallyUnrepresentableTimeLiterals.
@Test
public void testLocallyUnrepresentableTimeLiterals() {
LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp)
@Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss''").format(localTimeThatDidNotExist);
// this tests Presto and the QueryRunner
assertEquals(computeScalar(sql), localTimeThatDidNotExist);
// this tests H2QueryRunner
assertQuery(sql);
LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date)
sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight);
// this tests Presto and the QueryRunner
assertEquals(computeScalar(sql), localDateThatDidNotHaveMidnight);
// this tests H2QueryRunner
assertQuery(sql);
LocalTime localTimeThatDidNotOccurOn19700101 = LocalTime.of(0, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotOccurOn19700101.atDate(LocalDate.ofEpochDay(0))).isEmpty(), "This test assumes certain JVM time zone");
checkState(!Objects.equals(java.sql.Time.valueOf(localTimeThatDidNotOccurOn19700101).toLocalTime(), localTimeThatDidNotOccurOn19700101), "This test assumes certain JVM time zone");
sql = DateTimeFormatter.ofPattern("'SELECT TIME '''HH:mm:ss''").format(localTimeThatDidNotOccurOn19700101);
// this tests Presto and the QueryRunner
assertEquals(computeScalar(sql), localTimeThatDidNotOccurOn19700101);
// this tests H2QueryRunner
assertQuery(sql);
}
Aggregations