本文整理汇总了Java中scala.util.Either.isLeft方法的典型用法代码示例。如果您正苦于以下问题:Java Either.isLeft方法的具体用法?Java Either.isLeft怎么用?Java Either.isLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scala.util.Either
的用法示例。
在下文中一共展示了Either.isLeft方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeSql
import scala.util.Either; //导入方法依赖的package包/类
private InterpreterResult executeSql(String sql) {
try {
Either<String, Either<Joiner4All, Mapper4All>> result = dDriver.query(sql, null);
if (result.isLeft()) {
return new InterpreterResult(Code.ERROR, result.left().get().toString());
}
Either<Joiner4All, Mapper4All> goodResult =
(Either<Joiner4All, Mapper4All>) result.right().get();
if (goodResult.isLeft()) {
return new InterpreterResult(Code.SUCCESS, goodResult.left().get().toString());
} else {
return new InterpreterResult(Code.SUCCESS,
mapper4All2Zeppelin((Mapper4All) goodResult.right().get()));
}
} catch (Exception e) {
return new InterpreterResult(Code.ERROR, e.getMessage());
}
}
示例2: toGremlinQuery
import scala.util.Either; //导入方法依赖的package包/类
private GremlinQuery toGremlinQuery(String query, int limit, int offset) throws AtlasBaseException {
QueryParams params = validateSearchParams(limit, offset);
Either<NoSuccess, Expression> either = QueryParser.apply(query, params);
if (either.isLeft()) {
throw new AtlasBaseException(DISCOVERY_QUERY_FAILED, query);
}
Expression expression = either.right().get();
Expression validExpression = QueryProcessor.validate(expression);
GremlinQuery gremlinQuery = new GremlinTranslator(validExpression, graphPersistenceStrategy).translate();
if (LOG.isDebugEnabled()) {
LOG.debug("Translated Gremlin Query: {}", gremlinQuery.queryStr());
}
return gremlinQuery;
}
示例3: handle
import scala.util.Either; //导入方法依赖的package包/类
public Object handle(Request request, Response response) throws Exception {
KoauthRequest koauthRequest = requestMapper.map(request);
Either<KoauthResponse, String> authentication = provider.oauthenticate(koauthRequest);
if (authentication.isLeft()) {
KoauthResponse left = authentication.left().get();
if (left.getClass().equals(ResponseUnauthorized.class)) {
response.status(401);
return "You are treated as a guest.\n" + ((ResponseUnauthorized) left).body();
} else {
response.status(400);
return "You are treated as a guest.\n" + ((ResponseBadRequest) left).body();
}
} else {
String username = authentication.right().get();
return "You are " + username + ".";
}
}
示例4: requireCabalVersionMinimum
import scala.util.Either; //导入方法依赖的package包/类
protected void requireCabalVersionMinimum(double minimumVersion, @NotNull String errorMessage) throws RuntimeConfigurationException {
final HaskellBuildSettings buildSettings = HaskellBuildSettings.getInstance(getProject());
final String cabalPath = buildSettings.getCabalPath();
if (cabalPath.isEmpty()) {
throw new RuntimeConfigurationError("Path to cabal is not set.");
}
GeneralCommandLine cabalCmdLine = new GeneralCommandLine(cabalPath, "--numeric-version");
Either<ExecUtil.ExecError, String> result = ExecUtil.readCommandLine(cabalCmdLine);
if (result.isLeft()) {
//noinspection ThrowableResultOfMethodCallIgnored
ExecUtil.ExecError e = EitherUtil.unsafeGetLeft(result);
NotificationUtil.displaySimpleNotification(
NotificationType.ERROR, getProject(), "cabal", e.getMessage()
);
throw new RuntimeConfigurationError("Failed executing cabal to check its version: " + e.getMessage());
}
final String out = EitherUtil.unsafeGetRight(result);
final Matcher m = EXTRACT_CABAL_VERSION_REGEX.matcher(out);
if (!m.find()) {
throw new RuntimeConfigurationError("Could not parse cabal version: '" + out + "'");
}
final Double actualVersion = Double.parseDouble(m.group(1));
if (actualVersion < minimumVersion) {
throw new RuntimeConfigurationError(errorMessage);
}
}
示例5: aboutDataSource
import scala.util.Either; //导入方法依赖的package包/类
/**
* Left is error Right is Tuple <dimensions, metrics>
*
* @param name
* @param reqHeaders
* @return
*/
public Either<String, Tuple2<List<String>, List<String>>> aboutDataSource(String name, Map<String, String> reqHeaders) {
Either<String, Either<JSONArray, JSONObject>> resp = fireCommand("druid/coordinator/v1/metadata/datasources/" + name, null, reqHeaders);
if (resp.isLeft()) {
return new Left<>(resp.left().get());
}
Either<JSONArray, JSONObject> goodResp = resp.right().get();
if (goodResp.isRight()) {
JSONObject data = goodResp.right().get();
if (data.has("segments")) {
JSONArray segmentsArray = data.getJSONArray("segments");
if (segmentsArray.length() == 0) {
return new Left<>("No segments received..");
}
JSONObject firstItem = segmentsArray.getJSONObject(0);
String dims = firstItem.getString("dimensions");
String metrics = firstItem.getString("metrics");
return new Right<>(new Tuple2<>(Arrays.asList(dims.split(",")), Arrays.asList(metrics.split(","))));
} else {
return new Left<>("No segments key in the response..");
}
}
return new Left<>("Unexpected response " + goodResp.left().get().toString());
}
示例6: getTimeBoundary
import scala.util.Either; //导入方法依赖的package包/类
/**
* Get timeboundary.
*
* @param dataSource
* @param reqHeaders
* @return
* @throws java.lang.IllegalAccessException
*/
public Interval getTimeBoundary(String dataSource, Map<String, String> reqHeaders) throws IllegalAccessException {
Program<BaseStatementMeta> pgm = DCompiler.compileSql(format("SELECT FROM %s", dataSource));
Either<String,Either<Mapper4All,JSONArray>> res = fireQuery(pgm.nthStmnt(0).toString(), reqHeaders, true);
if (res.isLeft()) {
throw new IllegalAccessException(format("DataSource %s does not exist(or) check if druid is accessible, faced exception %s", dataSource, res.left().get()));
}
Mapper4All finalRes = res.right().get().left().get();// Thats because we know Time boundary cannot be a Join result!!
int min = finalRes.baseFieldNames.indexOf("minTime");
int max = finalRes.baseFieldNames.indexOf("maxTime");
if (finalRes.baseAllRows.isEmpty()) {// Possible when table does not exist.
throw new IllegalAccessException("Either table does not exist(or) druid is not accessible");
}
List<Object> row = finalRes.baseAllRows.get(0);// Only 1 element is returned in Timeboundary.
return new Interval(row.get(min).toString(), row.get(max).toString());
}
示例7: getCompiledAST
import scala.util.Either; //导入方法依赖的package包/类
/**
* Get an in memory representation of broken SQL query. This may require
* contacting druid for resolving dimensions Vs metrics for SELECT queries
* hence it also optionally accepts HTTP request headers to be sent out.
*
* @param sqlQuery
* @param namedParams
* @param reqHeaders
* @return
* @throws java.lang.Exception
*/
public Program<BaseStatementMeta> getCompiledAST(String sqlQuery, NamedParameters namedParams, Map<String, String> reqHeaders) throws Exception {
Program<BaseStatementMeta> pgm = DCompiler.compileSql(preprocessSqlQuery(sqlQuery, namedParams));
for (BaseStatementMeta stmnt : pgm.getAllStmnts()) {
if (stmnt instanceof QueryMeta) {
QueryMeta query = (QueryMeta) stmnt;
if (query.queryType == RequestType.SELECT) {//classifyColumnsToDimAndMetrics
Either<String, Tuple2<List<String>, List<String>>> dataSourceDescRes = coordinator.aboutDataSource(stmnt.dataSource, reqHeaders);
if (dataSourceDescRes.isLeft()) {
throw new Exception("Datasource info either not available (or)could not be loaded ." + dataSourceDescRes.left().get());
} else {
((SelectQueryMeta) query).postProcess(dataSourceDescRes.right().get());
}
}
} else if (stmnt instanceof InsertMeta) {//TODO: Handle this.
} else if (stmnt instanceof DeleteMeta) {//TODO: Handle this.
} else if (stmnt instanceof DropMeta) {//TODO: Handle this.
}
}
//TODO: Do something if pgm is invalid !!!
pgm.isValid();
return pgm;
}
示例8: exec
import scala.util.Either; //导入方法依赖的package包/类
@Nullable
public static String exec(@NotNull Project project, @NotNull String workingDirectory, @NotNull String ghcModPath,
@NotNull String command, @NotNull String ghcModFlags, String... params) {
if (!validateGhcVersion(project, ghcModPath, ghcModFlags)) return null;
GeneralCommandLine commandLine = new GeneralCommandLine(ghcModPath);
GhcModUtil.updateEnvironment(project, commandLine.getEnvironment());
ParametersList parametersList = commandLine.getParametersList();
parametersList.addParametersString(ghcModFlags);
parametersList.add(command);
parametersList.addAll(params);
// setWorkDirectory is deprecated but is needed to work with IntelliJ 13 which does not have withWorkDirectory.
commandLine.setWorkDirectory(workingDirectory);
// Make sure we can actually see the errors.
commandLine.setRedirectErrorStream(true);
HaskellToolsConsole toolConsole = HaskellToolsConsole.get(project);
toolConsole.writeInput(ToolKey.GHC_MOD_KEY, "Using working directory: " + workingDirectory);
toolConsole.writeInput(ToolKey.GHC_MOD_KEY, commandLine.getCommandLineString());
Either<ExecUtil.ExecError, String> result = ExecUtil.readCommandLine(commandLine);
if (result.isLeft()) {
//noinspection ThrowableResultOfMethodCallIgnored
ExecUtil.ExecError e = EitherUtil.unsafeGetLeft(result);
toolConsole.writeError(ToolKey.GHC_MOD_KEY, e.getMessage());
NotificationUtil.displayToolsNotification(
NotificationType.ERROR, project, "ghc-mod", e.getMessage()
);
return null;
}
String out = EitherUtil.unsafeGetRight(result);
toolConsole.writeOutput(ToolKey.GHC_MOD_KEY, out);
return out;
}
示例9: executeWork
import scala.util.Either; //导入方法依赖的package包/类
/**
* Run the jobs which are eligible to run.
*/
private void executeWork() {
StatusTrail st = null;
if ((st = newWorkQueue.removeFirst()) != null) {
log.info("New task {}", st);
DataSource ds = db().getDataSource(st.getDataSourceId());//TODO: Cache the DataSource table.
String frozenSql = materializeTemplate(ds.getTemplateSql(), st.getNominalTime(), st.getNominalTime(), st.getNominalTime() + JobFreq.valueOf(ds.getFrequency()).inMillis());
log.info("Sql is {}", frozenSql);
Either<String, Either<Joiner4All, Mapper4All>> result = druidDriver.query(frozenSql, null, null, false, "sql", true);
if (result.isLeft()) {
String taskId = result.left().get();// Because we forced async mode we will get back taskId.
log.info("Submitted task {} to overlord ", taskId);
st.setTaskId(taskId);
st.setStatus(JobStatus.in_progress);
db().updateStatusTrail(st);
// Quite possible st may exist in Q- when an item is removed and executed
// during which time if work generator generates the same st and
// updates Q because it still found the ST as not_done.
if (newWorkQueue.contains(st)) {
newWorkQueue.remove(st);
log.warn("newWorkQueue had one more entry for st {} which was just set to in_progress", st);
}
} else {// Something wrong. Insert always returns left.
log.error("Got weird result (expected to run insert) {}", result.right().get());
}
}
}
示例10: getDimensions
import scala.util.Either; //导入方法依赖的package包/类
public List<String> getDimensions(String name, Map<String, String> reqHeaders) {
Either<String,Tuple2<List<String>,List<String>>> aboutDataSource = aboutDataSource(name, reqHeaders);
if (aboutDataSource.isLeft()) {
return Lists.newArrayList();
}
return aboutDataSource.right().get()._1();
}
示例11: getMetrics
import scala.util.Either; //导入方法依赖的package包/类
public List<String> getMetrics(String name, Map<String, String> reqHeaders) {
Either<String,Tuple2<List<String>,List<String>>> aboutDataSource = aboutDataSource(name, reqHeaders);
if (aboutDataSource.isLeft()) {
return Lists.newArrayList();
}
return aboutDataSource.right().get()._2();
}
示例12: query
import scala.util.Either; //导入方法依赖的package包/类
/**
* Use this to force asynchronous mode(indexer tasks). You can then call
* {@link DDataSource#pollIndexerTaskStatus(java.lang.String) } to poll and find
* status. Hard limit on any task is 2 hours. See {@link OverlordAccessor} for more.
* @param sqlOrJsonQuery
* @param namedParams
* @param reqHeaders
* @param printToConsole
* @param queryMode
* @param forceAsync
* @return
*/
public Either<String, Either<Joiner4All, Mapper4All>> query(String sqlOrJsonQuery, NamedParameters namedParams, Map<String, String> reqHeaders, boolean printToConsole, String queryMode, boolean forceAsync) {
if ("json".equals(queryMode)) {//TODO : #19
Either<String, Either<Mapper4All, JSONArray>> result = broker.fireQuery(sqlOrJsonQuery, reqHeaders, true);
if (result.isLeft()) return new Left<>(result.left().get());
if (printToConsole) {
println(result.right().get().left().get().toString());
}
return new Right<String, Either<Joiner4All, Mapper4All>>(new Right<Joiner4All, Mapper4All>(result.right().get().left().get()));
}
Program pgm;
try {
pgm = getCompiledAST(sqlOrJsonQuery, namedParams, reqHeaders);
} catch (Exception ex) {
return new Left<>(ex.getMessage());
}
if (pgm instanceof DeleteProgram) {
return new Left<>(deleteRows((DeleteProgram) pgm, reqHeaders, printToConsole));
} else if (pgm instanceof DropProgram) {
return new Left<>(dropTable((DropProgram) pgm, reqHeaders, printToConsole));
} else if (pgm instanceof InsertProgram) {
InsertProgram iPgm = (InsertProgram) pgm;
iPgm.print(printToConsole);
return new Left<>(overlord.fireTask(iPgm.nthStmnt(0), reqHeaders, !forceAsync && iPgm.waitForCompletion));
} else {
return selectRows((QueryProgram) pgm, reqHeaders, printToConsole);
}
}
示例13: testTimeSeriesBean
import scala.util.Either; //导入方法依赖的package包/类
@Test
public void testTimeSeriesBean() throws Exception {
Either<String, Either<List<TimeSeriesBean>, Map<Object, TimeSeriesBean>>> mapperRes = source.query(tsJoin, null, TimeSeriesBean.class, null, false);
if (mapperRes.isLeft()) {
throw new Exception(mapperRes.left().get());
}
Either<List<TimeSeriesBean>, Map<Object, TimeSeriesBean>> goodResult = mapperRes.right().get();
if (goodResult.isLeft()) {
PrettyPrint.print(goodResult.left().get());
} else {
PrettyPrint.print(new ArrayList<>(goodResult.right().get().values()));
}
}
示例14: testPositive
import scala.util.Either; //导入方法依赖的package包/类
public void testPositive(String query) throws Exception {
Either<String, Either<Joiner4All, Mapper4All>> result = source.query(query, null);
if (result.isLeft()) {
throw new Exception(result.left().get());
}
Either<Joiner4All, Mapper4All> goodResult = result.right().get();
if (goodResult.isLeft()) {
PrettyPrint.print(goodResult.left().get());
} else {
PrettyPrint.print(goodResult.right().get());
}
}