Search in sources :

Example 26 with Language

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);
}
Also used : Language(org.intellij.lang.annotations.Language) XmlBuilder(com.android.tools.idea.XmlBuilder) Test(org.junit.Test)

Example 27 with Language

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());
}
Also used : Language(org.intellij.lang.annotations.Language) XmlBuilder(com.android.tools.idea.XmlBuilder) Test(org.junit.Test)

Example 28 with Language

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");
}
Also used : Language(org.intellij.lang.annotations.Language) MaterializedResult(com.facebook.presto.testing.MaterializedResult)

Example 29 with Language

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));
}
Also used : Language(org.intellij.lang.annotations.Language) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Example 30 with Language

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) Language(org.intellij.lang.annotations.Language) LocalTime(java.time.LocalTime) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

Language (org.intellij.lang.annotations.Language)111 TableMetadata (com.facebook.presto.metadata.TableMetadata)25 Test (org.testng.annotations.Test)24 MaterializedResult (com.facebook.presto.testing.MaterializedResult)19 PsiFile (com.intellij.psi.PsiFile)18 MaterializedRow (com.facebook.presto.testing.MaterializedRow)11 List (java.util.List)11 Optional (java.util.Optional)11 Test (org.junit.Test)11 ImmutableList (com.google.common.collect.ImmutableList)10 Session (com.facebook.presto.Session)9 Constraint (com.facebook.presto.spi.Constraint)9 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)9 BasePlanTest (com.facebook.presto.sql.planner.assertions.BasePlanTest)8 ColumnConstraint (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)7 ExpectedValueProvider (com.facebook.presto.sql.planner.assertions.ExpectedValueProvider)7 PlanMatchPattern (com.facebook.presto.sql.planner.assertions.PlanMatchPattern)7 SortOrder (com.facebook.presto.common.block.SortOrder)6